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


C# INavigation.PointsToPrincipal方法代码示例

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


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

示例1: NavigationReferenceChangedAction

        private void NavigationReferenceChangedAction(InternalEntityEntry entry, INavigation navigation, object oldValue, object newValue)
        {
            var foreignKey = navigation.ForeignKey;
            var dependentProperties = foreignKey.Properties;
            var principalProperties = foreignKey.PrincipalKey.Properties;

            // TODO: What if the other entry is not yet being tracked?
            // Issue #323
            if (navigation.PointsToPrincipal())
            {
                if (newValue != null)
                {
                    SetForeignKeyValue(foreignKey, entry, entry.StateManager.GetOrCreateEntry(newValue));
                }
                else
                {
                    SetNullForeignKey(entry, dependentProperties);
                }
            }
            else
            {
                Debug.Assert(foreignKey.IsUnique);

                if (newValue != null)
                {
                    var dependentEntry = entry.StateManager.GetOrCreateEntry(newValue);

                    // Avoid eagerly setting FKs (which may be PKs) in un-tracked entities so as not to mess up
                    // Attach behavior that is based on key values.
                    if (dependentEntry.EntityState != EntityState.Detached)
                    {
                        SetForeignKeyValue(foreignKey, dependentEntry, entry);
                    }
                }

                if (oldValue != null)
                {
                    ConditionallySetNullForeignKey(entry.StateManager.GetOrCreateEntry(oldValue), dependentProperties, entry, principalProperties);
                }
            }

            if (oldValue != null)
            {
                ConditionallyClearInverse(entry, navigation, oldValue);
            }

            if (newValue != null)
            {
                SetInverse(entry, navigation, newValue);
            }
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:51,代码来源:NavigationFixer.cs

示例2: AddNavigationPropertyBindings

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

                var efEntityType = naviPair[i].DeclaringEntityType;
                if (!elementMap.ContainsKey(efEntityType))
                {
                    continue;
                }
                var entityType = elementMap[efEntityType] as IEdmEntityType;
                var navProperty = entityType.FindProperty(
                    naviPair[i].Name) as IEdmNavigationProperty;
                if (navProperty == null)
                {
                    continue;
                }
                var entitySet = (EdmEntitySet)container.EntitySets().
                    First(e => e.EntityType() == entityType);
                var targetEntitySet = container.EntitySets().
                    First(e => e.EntityType() == navProperty.ToEntityType());
                entitySet.AddNavigationTarget(navProperty, targetEntitySet);
            }
        }
开发者ID:adestis-mh,项目名称:RESTier,代码行数:32,代码来源:ModelProducer.cs

示例3: 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

示例4: TryFindPrincipal

        private object TryFindPrincipal(IStateManager stateManager, INavigation navigation, object dependentEntity)
        {
            if (navigation.PointsToPrincipal())
            {
                return _getterSource.GetAccessor(navigation).GetClrValue(dependentEntity);
            }

            // TODO: Perf
            foreach (var principalEntry in stateManager.Entries
                .Where(e => e.EntityType == navigation.ForeignKey.PrincipalEntityType))
            {
                if (navigation.IsCollection())
                {
                    if (_collectionAccessorSource.GetAccessor(navigation).Contains(principalEntry.Entity, dependentEntity))
                    {
                        return principalEntry.Entity;
                    }
                }
                else if (_getterSource.GetAccessor(navigation).GetClrValue(principalEntry.Entity) == dependentEntity)
                {
                    return principalEntry.Entity;
                }
            }

            return null;
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:26,代码来源:KeyPropagator.cs

示例5: 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

示例6: SetInverse

        private void SetInverse(InternalEntityEntry entry, INavigation navigation, object entity)
        {
            var inverse = navigation.FindInverse();

            if (inverse != null)
            {
                var inverseEntry = entry.StateManager.GetOrCreateEntry(entity);

                if (inverse.IsCollection())
                {
                    var collectionAccessor = _collectionAccessorSource.GetAccessor(inverse);

                    if (!collectionAccessor.Contains(entity, entry.Entity))
                    {
                        collectionAccessor.Add(entity, entry.Entity);
                    }
                }
                else
                {
                    var oldEntity = _getterSource.GetAccessor(inverse).GetClrValue(entity);
                    if (oldEntity != null
                        && oldEntity != entry.Entity)
                    {
                        var oldEntry = entry.StateManager.GetOrCreateEntry(oldEntity);
                        if (navigation.PointsToPrincipal())
                        {
                            Unfixup(navigation, inverseEntry, oldEntry);
                            SetNullForeignKey(oldEntry, navigation.ForeignKey.Properties);
                        }
                        else
                        {
                            Unfixup(navigation, oldEntry, inverseEntry);
                        }
                    }

                    _setterSource.GetAccessor(inverse).SetClrValue(entity, entry.Entity);
                }

                inverseEntry.RelationshipsSnapshot.TakeSnapshot(inverse);
            }
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:41,代码来源:NavigationFixer.cs

示例7: Unfixup

        private void Unfixup(INavigation navigation, InternalEntityEntry oldPrincipalEntry, InternalEntityEntry dependentEntry)
        {
            if (navigation.PointsToPrincipal())
            {
                _setterSource.GetAccessor(navigation).SetClrValue(dependentEntry.Entity, null);

                dependentEntry.RelationshipsSnapshot.TakeSnapshot(navigation);
            }
            else
            {
                if (navigation.IsCollection())
                {
                    var collectionAccessor = _collectionAccessorSource.GetAccessor(navigation);
                    if (collectionAccessor.Contains(oldPrincipalEntry.Entity, dependentEntry.Entity))
                    {
                        collectionAccessor.Remove(oldPrincipalEntry.Entity, dependentEntry.Entity);
                    }
                }
                else
                {
                    _setterSource.GetAccessor(navigation).SetClrValue(oldPrincipalEntry.Entity, null);
                }
            }
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:24,代码来源:NavigationFixer.cs


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