本文整理汇总了C#中IEdmEntityType.DeclaredNavigationProperties方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmEntityType.DeclaredNavigationProperties方法的具体用法?C# IEdmEntityType.DeclaredNavigationProperties怎么用?C# IEdmEntityType.DeclaredNavigationProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmEntityType
的用法示例。
在下文中一共展示了IEdmEntityType.DeclaredNavigationProperties方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
}
}