本文整理汇总了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));
}
}
}
}
示例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;
}
示例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;
}