当前位置: 首页>>代码示例>>C#>>正文


C# IEdmEntityType.DeclaredNavigationProperties方法代码示例

本文整理汇总了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);
                    }
                }
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:70,代码来源:EdmToStockModelConverter.cs


注:本文中的IEdmEntityType.DeclaredNavigationProperties方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。