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


C# IEntityType.GetPrimaryKey方法代码示例

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


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

示例1: EntityTrackingInfo

        public EntityTrackingInfo(
            [NotNull] IEntityKeyFactorySource entityKeyFactorySource,
            [NotNull] IClrAccessorSource<IClrPropertyGetter> clrPropertyGetterSource,
            [NotNull] QueryCompilationContext queryCompilationContext,
            [NotNull] QuerySourceReferenceExpression querySourceReferenceExpression,
            [NotNull] IEntityType entityType)
        {
            Check.NotNull(entityKeyFactorySource, nameof(entityKeyFactorySource));
            Check.NotNull(clrPropertyGetterSource, nameof(clrPropertyGetterSource));
            Check.NotNull(querySourceReferenceExpression, nameof(querySourceReferenceExpression));
            Check.NotNull(entityType, nameof(entityType));
            Check.NotNull(queryCompilationContext, nameof(queryCompilationContext));

            QuerySourceReferenceExpression = querySourceReferenceExpression;

            _entityType = entityType;
            _queryCompilationContext = queryCompilationContext;
            _entityKeyFactorySource = entityKeyFactorySource;
            _clrPropertyGetterSource = clrPropertyGetterSource;

            _entityKeyProperties = _entityType.GetPrimaryKey().Properties;

            _entityKeyFactory = _entityKeyFactorySource.GetKeyFactory(_entityType.GetPrimaryKey());

            _includedNavigationPaths
                = _queryCompilationContext
                    .GetTrackableIncludes(querySourceReferenceExpression.ReferencedQuerySource);

            if (_includedNavigationPaths != null)
            {
                _includedEntityTrackingInfos = new Dictionary<INavigation, IncludedEntityTrackingInfo>();

                foreach (var navigation
                    in _includedNavigationPaths.SelectMany(ns => ns))
                {
                    if (!_includedEntityTrackingInfos.ContainsKey(navigation))
                    {
                        var targetEntityType = navigation.GetTargetType();
                        var targetKey = targetEntityType.GetPrimaryKey();

                        _includedEntityTrackingInfos.Add(
                            navigation,
                            new IncludedEntityTrackingInfo(
                                targetEntityType,
                                _entityKeyFactorySource.GetKeyFactory(targetKey),
                                targetKey.Properties));
                    }
                }
            }
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:50,代码来源:EntityTrackingInfo.cs

示例2: StartTracking

        public virtual InternalEntityEntry StartTracking(IEntityType entityType, object entity, IValueReader valueReader)
        {
            // TODO: Perf: Pre-compute this for speed
            var keyProperties = entityType.GetPrimaryKey().Properties;
            var keyValue = _keyFactorySource.GetKeyFactory(keyProperties).Create(entityType, keyProperties, valueReader);

            if (keyValue == EntityKey.InvalidEntityKey)
            {
                throw new InvalidOperationException(Strings.InvalidPrimaryKey(entityType.DisplayName()));
            }

            var existingEntry = TryGetEntry(keyValue);

            if (existingEntry != null)
            {
                if (existingEntry.Entity != entity)
                {
                    throw new InvalidOperationException(Strings.IdentityConflict(entityType.DisplayName()));
                }

                return existingEntry;
            }

            var newEntry = _subscriber.SnapshotAndSubscribe(_factory.Create(this, entityType, entity, valueReader));

            _identityMap.Add(keyValue, newEntry);
            _entityReferenceMap[entity] = newEntry;

            newEntry.SetEntityState(EntityState.Unchanged);

            return newEntry;
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:32,代码来源:StateManager.cs

示例3: CreateEntityType

        private static IEdmEntityType CreateEntityType(
            IModel efModel, IEntityType efEntityType,
            EdmModel model, out List<EdmStructuralProperty> concurrencyProperties)
        {
            // TODO GitHubIssue#36 : support complex and entity inheritance
            var entityType = new EdmEntityType(
                efEntityType.ClrType.Namespace, efEntityType.ClrType.Name);
            concurrencyProperties = null;
            foreach (var efProperty in efEntityType.GetProperties())
            {
                var type = ModelProducer.GetPrimitiveTypeReference(efProperty);
                if (type != null)
                {
                    string defaultValue = null;

                    if (efProperty.SqlServer().DefaultValue != null)
                    {
                        defaultValue = efProperty.SqlServer().DefaultValue.ToString();
                    }

                    var property = entityType.AddStructuralProperty(
                        efProperty.Name, type, defaultValue,
                        EdmConcurrencyMode.None); // alway None:replaced by OptimisticConcurrency annotation

                    // TODO GitHubIssue#57: Complete EF7 to EDM model mapping
                    if (efProperty.StoreGeneratedAlways)
                    {
                        SetComputedAnnotation(model, property);
                    }

                    if (efProperty.IsConcurrencyToken)
                    {
                        concurrencyProperties = concurrencyProperties ?? new List<EdmStructuralProperty>();
                        concurrencyProperties.Add(property);
                    }
                }
            }

            var key = efEntityType.GetPrimaryKey();
            if (key != null)
            {
                entityType.AddKeys(key.Properties
                    .Select(p => entityType.FindProperty(p.Name))
                    .Cast<IEdmStructuralProperty>());
            }
            return entityType;
        }
开发者ID:adestis-mh,项目名称:RESTier,代码行数:47,代码来源:ModelProducer.cs


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