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


C# INavigation.GetTargetType方法代码示例

本文整理汇总了C#中INavigation.GetTargetType方法的典型用法代码示例。如果您正苦于以下问题:C# INavigation.GetTargetType方法的具体用法?C# INavigation.GetTargetType怎么用?C# INavigation.GetTargetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在INavigation的用法示例。


在下文中一共展示了INavigation.GetTargetType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddNavigationProperties

        private static void AddNavigationProperties(
            IModel efModel, INavigation navi,
            EdmModel model, IDictionary<IAnnotatable, IEdmElement> elementMap)
        {
            if (!navi.PointsToPrincipal())
            {
                return;
            }
            var naviPair = new INavigation[] { navi, navi.FindInverse() };
            var navPropertyInfos = new EdmNavigationPropertyInfo[2];
            for (var i = 0; i < 2; i++)
            {
                var efEnd = naviPair[i];
                if (efEnd == null) continue;

                var efEntityType = efEnd.DeclaringEntityType;
                if (!elementMap.ContainsKey(efEntityType))
                {
                    continue;
                }
                var entityType = elementMap[efEntityType] as IEdmEntityType;
                var efTargetEntityType = naviPair[i].GetTargetType();
                if (!elementMap.ContainsKey(efTargetEntityType))
                {
                    continue;
                }
                var targetEntityType = elementMap[
                    efTargetEntityType] as IEdmEntityType;
                navPropertyInfos[i] = new EdmNavigationPropertyInfo()
                {
                    ContainsTarget = false,
                    Name = naviPair[i].Name,
                    // TODO GitHubIssue#57: Complete EF7 to EDM model mapping
                    //OnDelete = efEnd.DeleteBehavior == OperationAction.Cascade
                    //    ? EdmOnDeleteAction.Cascade : EdmOnDeleteAction.None,
                    OnDelete = EdmOnDeleteAction.None,
                    Target = targetEntityType,
                    TargetMultiplicity = ModelProducer.GetEdmMultiplicity(
                        naviPair[i]),
                };
                var foreignKey = naviPair[i].ForeignKey;
                if (foreignKey != null && naviPair[i].PointsToPrincipal())
                {
                    navPropertyInfos[i].DependentProperties = foreignKey.Properties
                        .Select(p => entityType.FindProperty(p.Name) as IEdmStructuralProperty);
                    navPropertyInfos[i].PrincipalProperties = foreignKey.PrincipalKey.Properties
                        .Select(p => targetEntityType.FindProperty(p.Name) as IEdmStructuralProperty);
                }
            }
            if (navPropertyInfos[0] == null && navPropertyInfos[1] != null)
            {
                var efEntityType = navi.GetTargetType();
                var entityType = elementMap[efEntityType] as EdmEntityType;
                if (entityType.FindProperty(navPropertyInfos[1].Name) == null)
                {
                    entityType.AddUnidirectionalNavigation(navPropertyInfos[1]);
                }
            }
            if (navPropertyInfos[0] != null && navPropertyInfos[1] == null)
            {
                var efEntityType = navi.DeclaringEntityType;
                var entityType = elementMap[efEntityType] as EdmEntityType;
                if (entityType.FindProperty(navPropertyInfos[0].Name) == null)
                {
                    entityType.AddUnidirectionalNavigation(navPropertyInfos[0]);
                }
            }
            if (navPropertyInfos[0] != null && navPropertyInfos[1] != null)
            {
                var efEntityType = navi.DeclaringEntityType;
                var entityType = elementMap[efEntityType] as EdmEntityType;
                if (entityType.FindProperty(navPropertyInfos[0].Name) == null)
                {
                    entityType.AddBidirectionalNavigation(
                        navPropertyInfos[0], navPropertyInfos[1]);
                }
            }
        }
开发者ID:adestis-mh,项目名称:RESTier,代码行数:78,代码来源:ModelProducer.cs

示例2: IncludeCore

        private IEntityType IncludeCore(
            object entity,
            INavigation navigation,
            out EntityKey primaryKey,
            out List<BufferedEntity> bufferedEntities,
            out Func<IValueReader, EntityKey> relatedKeyFactory)
        {
            var primaryKeyFactory
                = _entityKeyFactorySource
                    .GetKeyFactory(navigation.ForeignKey.PrincipalKey.Properties);

            var foreignKeyFactory
                = _entityKeyFactorySource
                    .GetKeyFactory(navigation.ForeignKey.Properties);

            var targetEntityType = navigation.GetTargetType();

            if (!_byEntityInstance.TryGetValue(entity, out bufferedEntities))
            {
                _byEntityInstance.Add(entity, bufferedEntities = new List<BufferedEntity> { null });

                var entry = _stateManager.TryGetEntry(entity);

                Debug.Assert(entry != null);

                primaryKey
                    = navigation.PointsToPrincipal
                        ? entry.GetDependentKeySnapshot(navigation.ForeignKey)
                        : entry.GetPrimaryKeyValue();
            }
            else
            {
                // if entity is already in state manager it can't be added to the buffer. 'null' value was added to signify that
                // this means relevant key should be acquired  from state manager rather than buffered reader
                if (bufferedEntities[0] == null)
                {
                    var entry = _stateManager.TryGetEntry(entity);

                    Debug.Assert(entry != null);

                    primaryKey
                        = navigation.PointsToPrincipal
                            ? entry.GetDependentKeySnapshot(navigation.ForeignKey)
                            : entry.GetPrimaryKeyValue();
                }
                else
                {
                    primaryKey
                        = navigation.PointsToPrincipal
                            ? foreignKeyFactory
                                .Create(
                                    targetEntityType,
                                    navigation.ForeignKey.Properties,
                                    bufferedEntities[0].ValueReader)
                            : primaryKeyFactory
                                .Create(
                                    navigation.EntityType,
                                    navigation.ForeignKey.PrincipalKey.Properties,
                                    bufferedEntities[0].ValueReader);
                }
            }

            if (navigation.PointsToPrincipal)
            {
                relatedKeyFactory
                    = valueReader =>
                        primaryKeyFactory
                            .Create(
                                targetEntityType,
                                navigation.ForeignKey.PrincipalKey.Properties,
                                valueReader);
            }
            else
            {
                relatedKeyFactory
                    = valueReader =>
                        foreignKeyFactory
                            .Create(
                                navigation.EntityType,
                                navigation.ForeignKey.Properties,
                                valueReader);
            }

            return targetEntityType;
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:85,代码来源:QueryBuffer.cs

示例3: IncludeCore

        private IEntityType IncludeCore(
            object entity,
            INavigation navigation,
            out EntityKey primaryKey,
            out Func<ValueBuffer, EntityKey> relatedKeyFactory)
        {
            var primaryKeyFactory
                = _entityKeyFactorySource
                    .GetKeyFactory(navigation.ForeignKey.PrincipalKey.Properties);

            var foreignKeyFactory
                = _entityKeyFactorySource
                    .GetKeyFactory(navigation.ForeignKey.Properties);

            var targetEntityType = navigation.GetTargetType();

            object boxedValueBuffer;
            if (!_valueBuffers.TryGetValue(entity, out boxedValueBuffer))
            {
                var entry = _stateManager.TryGetEntry(entity);

                Debug.Assert(entry != null);

                primaryKey
                    = navigation.PointsToPrincipal()
                        ? entry.GetDependentKeySnapshot(navigation.ForeignKey)
                        : entry.GetPrimaryKeyValue();
            }
            else
            {
                primaryKey
                    = navigation.PointsToPrincipal()
                        ? foreignKeyFactory
                            .Create(
                                targetEntityType.RootType(),
                                navigation.ForeignKey.Properties,
                                (ValueBuffer)boxedValueBuffer)
                        : primaryKeyFactory
                            .Create(
                                navigation.DeclaringEntityType.RootType(),
                                navigation.ForeignKey.PrincipalKey.Properties,
                                (ValueBuffer)boxedValueBuffer);
            }

            if (navigation.PointsToPrincipal())
            {
                relatedKeyFactory
                    = valueBuffer =>
                        primaryKeyFactory
                            .Create(
                                targetEntityType.RootType(),
                                navigation.ForeignKey.PrincipalKey.Properties,
                                valueBuffer);
            }
            else
            {
                relatedKeyFactory
                    = valueBuffer =>
                        foreignKeyFactory
                            .Create(
                                navigation.DeclaringEntityType.RootType(),
                                navigation.ForeignKey.Properties,
                                valueBuffer);
            }

            return targetEntityType;
        }
开发者ID:JamesWang007,项目名称:EntityFramework,代码行数:67,代码来源:QueryBuffer.cs

示例4: IncludeCore

        private IEntityType IncludeCore(
            object entity,
            INavigation navigation,
            out IKeyValue primaryKeyValue,
            out Func<ValueBuffer, IKeyValue> relatedKeyFactory)
        {
            var keyFactory
                = _keyValueFactorySource
                    .GetKeyFactory(navigation.ForeignKey.PrincipalKey);

            var targetEntityType = navigation.GetTargetType();

            object boxedValueBuffer;
            if (!_valueBuffers.TryGetValue(entity, out boxedValueBuffer))
            {
                var entry = _stateManager.TryGetEntry(entity);

                Debug.Assert(entry != null);

                primaryKeyValue
                    = navigation.IsDependentToPrincipal()
                        ? entry.GetDependentKeyValue(navigation.ForeignKey)
                        : entry.GetPrimaryKeyValue();
            }
            else
            {
                primaryKeyValue
                    = navigation.IsDependentToPrincipal()
                        ? keyFactory
                            .Create(
                                navigation.ForeignKey.Properties,
                                (ValueBuffer)boxedValueBuffer)
                        : keyFactory
                            .Create(
                                navigation.ForeignKey.PrincipalKey.Properties,
                                (ValueBuffer)boxedValueBuffer);
            }

            if (navigation.IsDependentToPrincipal())
            {
                relatedKeyFactory
                    = valueBuffer =>
                        keyFactory
                            .Create(
                                navigation.ForeignKey.PrincipalKey.Properties,
                                valueBuffer);
            }
            else
            {
                relatedKeyFactory
                    = valueBuffer =>
                        keyFactory
                            .Create(
                                navigation.ForeignKey.Properties,
                                valueBuffer);
            }

            return targetEntityType;
        }
开发者ID:adwardliu,项目名称:EntityFramework,代码行数:59,代码来源:QueryBuffer.cs


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