本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmModel.FindType方法的典型用法代码示例。如果您正苦于以下问题:C# EdmModel.FindType方法的具体用法?C# EdmModel.FindType怎么用?C# EdmModel.FindType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Edm.Library.EdmModel
的用法示例。
在下文中一共展示了EdmModel.FindType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAmbiguousBinding
public void CreateAmbiguousBinding()
{
EdmModel model = new EdmModel();
EdmComplexType c1 = new EdmComplexType("Ambiguous", "Binding");
EdmComplexType c2 = new EdmComplexType("Ambiguous", "Binding");
EdmComplexType c3 = new EdmComplexType("Ambiguous", "Binding");
model.AddElement(c1);
Assert.AreEqual(c1, model.FindType("Ambiguous.Binding"), "Single item resolved");
model.AddElement(c2);
model.AddElement(c3);
IEdmNamedElement ambiguous = model.FindType("Ambiguous.Binding");
Assert.IsTrue(ambiguous.IsBad(), "Ambiguous binding is bad");
Assert.AreEqual(EdmErrorCode.BadAmbiguousElementBinding, ambiguous.Errors().First().ErrorCode, "Ambiguous");
c1 = null;
c2 = new EdmComplexType("Ambiguous", "Binding2");
Assert.IsTrue
(
model.SchemaElements.OfType<IEdmComplexType>().Count() == 3 && model.SchemaElements.OfType<IEdmComplexType>().All(n => n.FullName() == "Ambiguous.Binding"),
"The model must be immutable."
);
}
示例2: VerifyTimeOfDayValueReader
private void VerifyTimeOfDayValueReader(string payload, string edmTypeName, object expectedResult)
{
IEdmModel model = new EdmModel();
IEdmPrimitiveTypeReference typeReference = new EdmPrimitiveTypeReference((IEdmPrimitiveType)model.FindType(edmTypeName), true);
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(payload));
object actualValue;
using (ODataJsonLightInputContext inputContext = new ODataJsonLightInputContext(
ODataFormat.Json,
stream,
JsonLightUtils.JsonLightStreamingMediaType,
Encoding.UTF8,
new ODataMessageReaderSettings(),
/*readingResponse*/ true,
/*synchronous*/ true,
model,
/*urlResolver*/ null))
{
ODataJsonLightPropertyAndValueDeserializer deserializer = new ODataJsonLightPropertyAndValueDeserializer(inputContext);
deserializer.JsonReader.Read();
actualValue = deserializer.ReadNonEntityValue(
/*payloadTypeName*/ null,
typeReference,
/*duplicatePropertyNamesChecker*/ null,
/*collectionValidator*/ null,
/*validateNullValue*/ true,
/*isTopLevelPropertyValue*/ true,
/*insideComplexValue*/ false,
/*propertyName*/ null);
}
actualValue.Should().Be(expectedResult, "payload ->{0}<- for type '{1}'", payload, edmTypeName);
}
示例3: ConvertToStockVocabularyAnnotatable
private IEdmVocabularyAnnotatable ConvertToStockVocabularyAnnotatable(IEdmElement edmAnnotatable, EdmModel stockModel)
{
// TODO: Need to provide a better way to get more details on IEdmVocabularyAnnotation.Target.
IEdmVocabularyAnnotatable stockAnnotatable = null;
if (edmAnnotatable is IEdmEntityType)
{
var edmEntityType = edmAnnotatable as IEdmEntityType;
stockAnnotatable = stockModel.FindType(edmEntityType.FullName()) as IEdmVocabularyAnnotatable;
ExceptionUtilities.CheckObjectNotNull(stockAnnotatable, "The FindType method must be successful.");
}
else if (edmAnnotatable is IEdmProperty)
{
var edmProperty = edmAnnotatable as IEdmProperty;
if (edmProperty.DeclaringType is IEdmSchemaElement)
{
var stockSchemaElement = stockModel.FindType(((IEdmSchemaElement)edmProperty.DeclaringType).FullName());
ExceptionUtilities.CheckObjectNotNull(stockAnnotatable, "The FindType method must be successful.");
stockAnnotatable = ((IEdmStructuredType)stockSchemaElement).FindProperty(edmProperty.Name);
}
else
{
throw new NotImplementedException();
}
}
else if (edmAnnotatable is IEdmEntitySet)
{
var edmEntitySet = edmAnnotatable as IEdmEntitySet;
// TODO: No backpointer to the Entity Container from EntitySet in the API. Is this OK?
stockAnnotatable = stockModel.EntityContainer.EntitySets().Single(m => m.Name == edmEntitySet.Name);
}
else if (edmAnnotatable is IEdmEnumType)
{
var edmEnumType = edmAnnotatable as IEdmEnumType;
stockAnnotatable = stockModel.FindType(edmEnumType.FullName());
}
else
{
throw new NotImplementedException();
}
return stockAnnotatable;
}
示例4: AddOperationWhileTypeHasSameName
public void AddOperationWhileTypeHasSameName()
{
EdmModel model = new EdmModel();
EdmComplexType c1 = new EdmComplexType("Ambiguous", "Binding");
IEdmOperation o1 = new EdmFunction("Ambiguous", "Binding", EdmCoreModel.Instance.GetInt16(true));
IEdmOperation o2 = new EdmFunction("Ambiguous", "Binding", EdmCoreModel.Instance.GetInt16(true));
IEdmOperation o3 = new EdmFunction("Ambiguous", "Binding", EdmCoreModel.Instance.GetInt16(true));
model.AddElement(o1);
Assert.AreEqual(1, model.FindOperations("Ambiguous.Binding").Count(), "First function was correctly added to operation group");
model.AddElement(o2);
Assert.AreEqual(2, model.FindOperations("Ambiguous.Binding").Count(), "Second function was correctly added to operation group");
model.AddElement(c1);
model.AddElement(o3);
Assert.AreEqual(3, model.FindOperations("Ambiguous.Binding").Count(), "Third function was correctly added to operation group");
Assert.AreEqual(c1, model.FindType("Ambiguous.Binding"), "Single item resolved");
}
示例5: AmbiguousTypeTest
public void AmbiguousTypeTest()
{
EdmModel model = new EdmModel();
IEdmSchemaType type1 = new StubEdmComplexType("Foo", "Bar");
IEdmSchemaType type2 = new StubEdmComplexType("Foo", "Bar");
IEdmSchemaType type3 = new StubEdmComplexType("Foo", "Bar");
model.AddElement(type1);
Assert.AreEqual(type1, model.FindType("Foo.Bar"), "Correct item.");
model.AddElement(type2);
model.AddElement(type3);
IEdmSchemaType ambiguous = model.FindType("Foo.Bar");
Assert.IsTrue(ambiguous.IsBad(), "Ambiguous binding is bad");
Assert.AreEqual(EdmSchemaElementKind.TypeDefinition, ambiguous.SchemaElementKind, "Correct schema element kind.");
Assert.AreEqual("Foo", ambiguous.Namespace, "Correct Namespace");
Assert.AreEqual("Bar", ambiguous.Name, "Correct Name");
Assert.AreEqual(EdmTypeKind.None, ambiguous.TypeKind, "Correct type kind.");
}
示例6: PropertyInStreamErrorTests
public void PropertyInStreamErrorTests()
{
EdmModel model = new EdmModel();
ODataProperty property = ObjectModelUtils.CreateDefaultPrimitiveProperties(model)[0];
var container = new EdmEntityContainer("TestModel", "DefaultContainer");
model.AddElement(container);
var entityType = model.FindType("TestModel.EntryWithPrimitiveProperties") as EdmEntityType;
this.Assert.AreEqual("Null", property.Name, "Expected null property to be the first primitive property.");
PayloadWriterTestDescriptor<ODataProperty>[] testDescriptors = new PayloadWriterTestDescriptor<ODataProperty>[]
{
new PayloadWriterTestDescriptor<ODataProperty>(this.Settings, property, (string)null, (string)null)
{
Model = model,
PayloadEdmElementContainer = entityType
},
};
this.CombinatorialEngineProvider.RunCombinations(
testDescriptors,
TestWriterUtils.InvalidSettingSelectors,
this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent,
(testDescriptor, selector, testConfiguration) =>
{
TestWriterUtils.WriteWithStreamErrors(
testDescriptor,
selector,
testConfiguration,
(messageWriter) => messageWriter.WriteProperty(testDescriptor.PayloadItems.Single()),
this.Assert);
});
}
示例7: ConvertToStockMember
private IEdmEnumMember ConvertToStockMember(IEdmEnumMember edmMember, IEdmModel edmModel, EdmModel stockModel)
{
var stockMemberDeclaringType = stockModel.FindType(GetFullName(edmMember.DeclaringType)) as IEdmEnumType;
var stockMember = new EdmEnumMember(
stockMemberDeclaringType,
edmMember.Name,
edmMember.Value
);
((EdmEnumType)stockMemberDeclaringType).AddMember(stockMember);
// TODO: Documentation
this.SetImmediateAnnotations(edmMember, stockMember, edmModel, stockModel);
return stockMember;
}
示例8: ConvertToStockStructuralProperty
private IEdmStructuralProperty ConvertToStockStructuralProperty(IEdmStructuralProperty edmProperty, IEdmModel edmModel, EdmModel stockModel)
{
var stockPropertyDeclaringType = stockModel.FindType(GetFullName(edmProperty.DeclaringType)) as IEdmStructuredType;
var stockProperty = new EdmStructuralProperty(
stockPropertyDeclaringType,
edmProperty.Name,
ConvertToStockTypeReference(edmProperty.Type, stockModel),
edmProperty.DefaultValueString,
edmProperty.ConcurrencyMode
);
((EdmStructuredType)stockPropertyDeclaringType).AddProperty(stockProperty);
// TODO: Documentation
this.SetImmediateAnnotations(edmProperty, stockProperty, edmModel, stockModel);
return stockProperty;
}
示例9: CreateFeedQueryCountDescriptors
private PayloadWriterTestDescriptor<ODataItem>[] CreateFeedQueryCountDescriptors()
{
Func<long?, ODataFeed> feedCreator = (c) =>
{
ODataFeed feed = ObjectModelUtils.CreateDefaultFeed();
feed.Count = c;
return feed;
};
long?[] counts = new long?[] { 0, 1, 2, 1000, -1 - 10, long.MaxValue, long.MinValue, null };
EdmModel model = new EdmModel();
ODataEntry entry = ObjectModelUtils.CreateDefaultEntryWithAtomMetadata("DefaultEntitySet", "DefaultEntityType", model);
var container = model.FindEntityContainer("DefaultContainer");
var entitySet = container.FindEntitySet("DefaultEntitySet") as EdmEntitySet;
var entityType = model.FindType("TestModel.DefaultEntityType") as EdmEntityType;
var descriptors = counts.Select(count => new PayloadWriterTestDescriptor<ODataItem>(this.Settings, feedCreator(count),
(testConfiguration) =>
{
if (testConfiguration.IsRequest && count.HasValue)
{
return new WriterTestExpectedResults(this.Settings.ExpectedResultSettings)
{
ExpectedException2 = ODataExpectedExceptions.ODataException("ODataWriterCore_QueryCountInRequest")
};
}
if (testConfiguration.Format == ODataFormat.Atom)
{
if (count.HasValue)
{
return new AtomWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
{
Xml = @"<m:count xmlns:m =""" + TestAtomConstants.ODataMetadataNamespace + @""">" + count + "</m:count>",
FragmentExtractor = (result) => result.Elements(XName.Get("count", TestAtomConstants.ODataMetadataNamespace)).Single()
};
}
else
{
return new AtomWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
{
Xml = @"<nocount xmlns=""" + TestAtomConstants.ODataMetadataNamespace + @"""/>",
FragmentExtractor = (result) =>
{
var countElement = result.Elements(XName.Get("count", TestAtomConstants.ODataMetadataNamespace)).SingleOrDefault();
if (countElement == null)
{
countElement = new XElement(TestAtomConstants.ODataMetadataXNamespace + "nocount");
}
return countElement;
}
};
}
}
else if (testConfiguration.Format == ODataFormat.Json)
{
if (count.HasValue)
{
return new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
{
Json = "$(Indent)$(Indent)\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":\"" + count + "\"",
FragmentExtractor = (result) => result.Object().Property(JsonLightConstants.ODataCountAnnotationName)
};
}
else
{
return new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
{
Json = string.Join("$(NL)",
"[",
string.Empty,
"]"),
FragmentExtractor = (result) =>
{
return JsonLightWriterUtils.GetTopLevelFeedItemsArray(testConfiguration, result).RemoveAllAnnotations(true);
}
};
}
}
else
{
string formatName = testConfiguration.Format == null ? "null" : testConfiguration.Format.GetType().Name;
throw new NotSupportedException("Invalid format detected: " + formatName);
}
})
{
Model = model,
PayloadEdmElementContainer = entitySet,
PayloadEdmElementType = entityType,
});
return descriptors.ToArray();
}
示例10: ComplexValueIgnorePropertyNullValuesTest
public void ComplexValueIgnorePropertyNullValuesTest()
{
var versions = new Version[] {
null,
new Version(4, 0),
};
EdmModel edmModel = new EdmModel();
IEdmComplexType countryRegionType = edmModel.ComplexType("CountryRegion")
.Property("Name", EdmPrimitiveTypeKind.String)
.Property("CountryRegionCode", EdmPrimitiveTypeKind.String);
IEdmComplexType countryRegionNullType = edmModel.ComplexType("CountryRegionNull")
.Property("Name", EdmPrimitiveTypeKind.String)
.Property("CountryRegionCode", EdmPrimitiveTypeKind.String);
IEdmComplexType addressType = edmModel.ComplexType("Address")
.Property("Street", EdmPrimitiveTypeKind.String)
.Property("StreetNull", EdmCoreModel.Instance.GetString(true) as EdmTypeReference)
.Property("Numbers", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetInt32(false)) as EdmTypeReference)
.Property("CountryRegion", new EdmComplexTypeReference(countryRegionType, false))
.Property("CountryRegionNull", new EdmComplexTypeReference(countryRegionNullType, true));
edmModel.EntityType("Customer")
.KeyProperty("ID", EdmCoreModel.Instance.GetInt32(false) as EdmTypeReference)
.Property("Address", new EdmComplexTypeReference(addressType, false));
edmModel.Fixup();
this.CombinatorialEngineProvider.RunCombinations(
new ODataNullValueBehaviorKind[] { ODataNullValueBehaviorKind.Default, ODataNullValueBehaviorKind.DisableValidation, ODataNullValueBehaviorKind.IgnoreValue },
versions,
versions,
TestReaderUtils.ODataBehaviorKinds,
(nullPropertyValueReaderBehavior, dataServiceVersion, edmVersion, behaviorKind) =>
{
edmModel.SetEdmVersion(edmVersion);
// Now we set the 'IgnoreNullValues' annotation on all properties
IEdmComplexType edmAddressType = (IEdmComplexType)edmModel.FindType("TestModel.Address");
foreach (IEdmStructuralProperty edmProperty in edmAddressType.StructuralProperties())
{
edmModel.SetNullValueReaderBehavior(edmProperty, nullPropertyValueReaderBehavior);
}
EntityInstance customerPayload = PayloadBuilder.Entity("TestModel.Customer")
.PrimitiveProperty("ID", 1)
.Property("Address", PayloadBuilder.ComplexValue("TestModel.Address")
.PrimitiveProperty("Street", "One Microsoft Way")
.PrimitiveProperty("StreetNull", "One Microsoft Way")
.Property("Numbers", PayloadBuilder.PrimitiveMultiValue("Collection(Edm.Int32)").Item(1).Item(2))
.Property("CountryRegion", PayloadBuilder.ComplexValue("TestModel.CountryRegion")
.PrimitiveProperty("Name", "Austria")
.PrimitiveProperty("CountryRegionCode", "AUT"))
.Property("CountryRegionNull", PayloadBuilder.ComplexValue("TestModel.CountryRegionNull")
.PrimitiveProperty("Name", "Austria")
.PrimitiveProperty("CountryRegionCode", "AUT")));
var testCases = new[]
{
// Complex types that are not nullable should not allow null values.
// Null primitive property in the payload and non-nullable property in the model
new IgnoreNullValueTestCase
{
PropertyName = "Street",
ExpectedResponseException = ODataExpectedExceptions.ODataException("ReaderValidationUtils_NullNamedValueForNonNullableType", "Street", "Edm.String"),
},
// Null complex property in the payload and non-nullable property in the model
new IgnoreNullValueTestCase
{
PropertyName = "CountryRegion",
ExpectedResponseException = ODataExpectedExceptions.ODataException("ReaderValidationUtils_NullNamedValueForNonNullableType", "CountryRegion", "TestModel.CountryRegion"),
},
// Null collection property in the payload and non-nullable property in the model
new IgnoreNullValueTestCase
{
PropertyName = "Numbers",
ExpectedResponseException = ODataExpectedExceptions.ODataException("ReaderValidationUtils_NullNamedValueForNonNullableType", "Numbers", "Collection(Edm.Int32)"),
},
// Complex types that are nullable should allow null values.
// Null primitive property in the payload and nullable property in the model
new IgnoreNullValueTestCase
{
PropertyName = "StreetNull",
},
// Null complex property in the payload and nullable property in the model
new IgnoreNullValueTestCase
{
PropertyName = "CountryRegionNull",
},
};
Func<IgnoreNullValueTestCase, ReaderTestConfiguration, PayloadReaderTestDescriptor> createTestDescriptor =
(testCase, testConfig) =>
{
EntityInstance payloadValue = customerPayload.DeepCopy();
ComplexInstance payloadAddressValue = ((ComplexProperty)payloadValue.GetProperty("Address")).Value;
SetToNull(payloadAddressValue, testCase.PropertyName);
ComplexInstance resultValue = payloadValue;
if (testConfig.IsRequest && nullPropertyValueReaderBehavior == ODataNullValueBehaviorKind.IgnoreValue)
{
resultValue = customerPayload.DeepCopy();
ComplexInstance resultAddressValue = ((ComplexProperty)resultValue.GetProperty("Address")).Value;
//.........这里部分代码省略.........
示例11: FillStockContentsForEnum
private void FillStockContentsForEnum(IEdmEnumType edmType, IEdmModel edmModel, EdmModel stockModel)
{
var stockType = (IEdmEnumType)stockModel.FindType(edmType.FullName());
this.SetImmediateAnnotations(edmType, stockType, edmModel, stockModel);
foreach (var edmMember in edmType.Members)
{
ConvertToStockMember((IEdmEnumMember)edmMember, edmModel, stockModel);
}
}
示例12: FillStockContentsForComplex
private void FillStockContentsForComplex(IEdmComplexType edmType, IEdmModel edmModel, EdmModel stockModel)
{
var stockType = (EdmComplexType)stockModel.FindType(edmType.FullName());
this.SetImmediateAnnotations(edmType, stockType, edmModel, stockModel);
foreach (var edmProperty in edmType.DeclaredStructuralProperties())
{
ConvertToStockStructuralProperty((IEdmStructuralProperty)edmProperty, edmModel, stockModel);
}
}
示例13: FillStockContentsForEntityContainer
private void FillStockContentsForEntityContainer(IEdmEntityContainer edmContainer, IEdmModel edmModel, EdmModel stockModel)
{
var stockContainer = (EdmEntityContainer)stockModel.FindEntityContainer(edmContainer.FullName());
this.SetImmediateAnnotations(edmContainer, stockContainer, edmModel, stockModel);
foreach (var edmNavigationSource in edmContainer.Elements.OfType<IEdmNavigationSource>())
{
var stockEntityType = (EdmEntityType)stockModel.FindType(GetFullName(edmNavigationSource.EntityType()));
if (edmNavigationSource is IEdmSingleton)
{
stockContainer.AddSingleton(edmNavigationSource.Name, stockEntityType);
}
else
{
stockContainer.AddEntitySet(edmNavigationSource.Name, stockEntityType);
}
}
foreach (var stockNavigationSource in stockContainer.Elements.OfType<EdmNavigationSource>())
{
var stockEntityType = (EdmEntityType)stockModel.FindType(GetFullName(stockNavigationSource.EntityType()));
IEdmNavigationSource edmNavigationSource = edmContainer.FindEntitySet(stockNavigationSource.Name);
if (edmNavigationSource == null)
{
edmNavigationSource = edmContainer.FindSingleton(stockNavigationSource.Name);
}
var stockDerivedNavigations = GetAllNavigationFromDerivedTypesAndSelf(stockEntityType, stockModel);
foreach (var stockNavigationProperty in stockDerivedNavigations)
{
var edmNavigationProperty = edmNavigationSource.NavigationPropertyBindings.Select(n => n.NavigationProperty).SingleOrDefault(n => n.Name == stockNavigationProperty.Name);
if (edmNavigationProperty != null)
{
var targetEdmEntitySet = edmNavigationSource.FindNavigationTarget(edmNavigationProperty);
if (null != targetEdmEntitySet)
{
var targetEntitySetFromContainer = stockContainer.Elements.OfType<EdmEntitySet>().SingleOrDefault
(
n =>
GetBaseTypesAndSelf(((IEdmNavigationProperty)stockNavigationProperty).ToEntityType()).Select(m => GetFullName(m)).Contains(n.EntityType().FullName()) && n.Name == targetEdmEntitySet.Name
);
if (null == targetEntitySetFromContainer)
{
targetEntitySetFromContainer = stockContainer.Elements.OfType<EdmEntitySet>().SingleOrDefault
(
n =>
GetAllDerivedTypesAndSelf(((IEdmNavigationProperty)stockNavigationProperty).ToEntityType(), stockModel).Select(m => GetFullName(m)).Contains(n.EntityType().FullName()) && n.Name == targetEdmEntitySet.Name
);
}
stockNavigationSource.AddNavigationTarget(stockNavigationProperty, targetEntitySetFromContainer);
}
}
}
}
foreach (var edmOperationImport in edmContainer.OperationImports())
{
EdmOperationImport stockEdmOperationImport = null;
var edmActionImport = edmOperationImport as IEdmActionImport;
if (edmActionImport != null)
{
var newEdmAction = stockModel.FindDeclaredOperations(edmActionImport.Action.FullName()).OfType<IEdmAction>().FirstOrDefault() as EdmAction;
ExceptionUtilities.CheckObjectNotNull(newEdmAction, "cannot find action");
stockEdmOperationImport = stockContainer.AddActionImport(edmOperationImport.Name, newEdmAction, edmActionImport.EntitySet);
}
else
{
IEdmFunctionImport edmFunctionImport = edmOperationImport as IEdmFunctionImport;
ExceptionUtilities.CheckArgumentNotNull(edmFunctionImport, "edmFunctionImport");
var newEdmFunction = edmModel.FindDeclaredOperations(edmFunctionImport.Function.FullName()).OfType<IEdmFunction>().FirstOrDefault();
ExceptionUtilities.CheckObjectNotNull(newEdmFunction, "Expected to find an function: " + edmFunctionImport.Function.FullName());
stockEdmOperationImport = stockContainer.AddFunctionImport(edmFunctionImport.Name, newEdmFunction, edmFunctionImport.EntitySet, edmFunctionImport.IncludeInServiceDocument);
}
this.SetImmediateAnnotations(edmOperationImport, stockEdmOperationImport, edmModel, stockModel);
}
}
示例14: CreateNavigationPropertiesForStockEntity
private void CreateNavigationPropertiesForStockEntity(IEdmEntityType edmType, IEdmModel edmModel, EdmModel stockModel)
{
var stockType = (EdmEntityType)stockModel.FindType(edmType.FullName());
foreach (var edmNavigation in edmType.DeclaredNavigationProperties())
{
var stockToRoleType = (EdmEntityType)stockModel.FindType(edmNavigation.ToEntityType().FullName());
if (stockType.FindProperty(edmNavigation.Name) == null)
{
Func<IEnumerable<IEdmStructuralProperty>, IEnumerable<IEdmStructuralProperty>> createDependentProperties = (dependentProps) =>
{
if (dependentProps == null)
{
return null;
}
var stockDependentProperties = new List<IEdmStructuralProperty>();
foreach (var dependentProperty in dependentProps)
{
var stockDepProp = edmNavigation.DependentProperties() != null ? stockType.FindProperty(dependentProperty.Name) : stockToRoleType.FindProperty(dependentProperty.Name);
stockDependentProperties.Add((IEdmStructuralProperty)stockDepProp);
}
return stockDependentProperties;
};
Func<IEdmReferentialConstraint, IEdmEntityType, IEnumerable<IEdmStructuralProperty>> createPrincipalProperties = (refConstraint, principalType) =>
{
if (refConstraint == null)
{
return null;
}
return refConstraint.PropertyPairs.Select(p => (IEdmStructuralProperty)principalType.FindProperty(p.PrincipalProperty.Name));
};
var propertyInfo = new EdmNavigationPropertyInfo()
{
Name = edmNavigation.Name,
Target = stockToRoleType,
TargetMultiplicity = edmNavigation.TargetMultiplicity(),
DependentProperties = createDependentProperties(edmNavigation.DependentProperties()),
PrincipalProperties = createPrincipalProperties(edmNavigation.ReferentialConstraint, stockToRoleType),
ContainsTarget = edmNavigation.ContainsTarget,
OnDelete = edmNavigation.OnDelete
};
bool bidirectional = edmNavigation.Partner != null && edmNavigation.ToEntityType().FindProperty(edmNavigation.Partner.Name) != null;
if (bidirectional)
{
var partnerInfo = new EdmNavigationPropertyInfo()
{
Name = edmNavigation.Partner.Name,
TargetMultiplicity = edmNavigation.Partner.TargetMultiplicity(),
DependentProperties = createDependentProperties(edmNavigation.Partner.DependentProperties()),
PrincipalProperties = createPrincipalProperties(edmNavigation.Partner.ReferentialConstraint, stockType),
ContainsTarget = edmNavigation.Partner.ContainsTarget,
OnDelete = edmNavigation.Partner.OnDelete
};
stockType.AddBidirectionalNavigation(propertyInfo, partnerInfo);
}
else
{
stockType.AddUnidirectionalNavigation(propertyInfo);
}
}
}
}
示例15: FillStockContentsForEntityWithoutNavigation
private void FillStockContentsForEntityWithoutNavigation(IEdmEntityType edmType, IEdmModel edmModel, EdmModel stockModel)
{
var stockType = (EdmEntityType)stockModel.FindType(edmType.FullName());
this.SetImmediateAnnotations(edmType, stockType, edmModel, stockModel);
foreach (var edmProperty in edmType.DeclaredStructuralProperties())
{
ConvertToStockStructuralProperty((IEdmStructuralProperty)edmProperty, edmModel, stockModel);
}
if (edmType.DeclaredKey != null)
{
stockType.AddKeys(edmType.DeclaredKey.Select(n => stockType.FindProperty(n.Name) as IEdmStructuralProperty).ToArray());
}
}