本文整理汇总了C#中IEntityType类的典型用法代码示例。如果您正苦于以下问题:C# IEntityType类的具体用法?C# IEntityType怎么用?C# IEntityType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IEntityType类属于命名空间,在下文中一共展示了IEntityType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public override EntityKey Create(
IEntityType entityType, IReadOnlyList<IProperty> properties, IValueReader valueReader)
{
var components = new object[properties.Count];
for (var i = 0; i < properties.Count; i++)
{
var index = properties[i].Index;
if (valueReader.IsNull(index))
{
return EntityKey.InvalidEntityKey;
}
var value = _boxedValueReaders[i].ReadValue(valueReader, index);
if (Equals(value, _sentinels[i]))
{
return EntityKey.InvalidEntityKey;
}
components[i] = value;
}
return new CompositeEntityKey(entityType, components);
}
示例2: IsSingleQueryMode
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual bool IsSingleQueryMode(IEntityType entityType)
{
if (_singleQueryMode == false)
{
// Once we are out of SQM we are always out.
return false;
}
// If we already checked for self-refs then don't check again.
if (_singleQueryModeEntityType == entityType)
{
return true;
}
// Drop out if SQM for change of entity type or self-refs since query may not fix them up.
if (_singleQueryModeEntityType != null
|| entityType.GetNavigations().Any(n => entityType.IsSameHierarchy(n.GetTargetType())))
{
_singleQueryMode = false;
return false;
}
_singleQueryModeEntityType = entityType;
return true;
}
示例3: StartTracking
public virtual InternalEntityEntry StartTracking(
IEntityType entityType, EntityKey entityKey, object entity, ValueBuffer valueBuffer)
{
if (entityKey == EntityKey.InvalidEntityKey)
{
throw new InvalidOperationException(Strings.InvalidPrimaryKey(entityType.DisplayName()));
}
var existingEntry = TryGetEntry(entityKey);
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, valueBuffer));
_identityMap.Add(entityKey, newEntry);
_entityReferenceMap[entity] = newEntry;
newEntry.SetEntityState(EntityState.Unchanged);
return newEntry;
}
示例4: BindMixins
/// <summary>
/// Binds the mixins to the entity through change tracking.
/// </summary>
/// <param name="entry">The entity entry.</param>
/// <param name="entityType">The entity type.</param>
/// <param name="entity">The entity instance.</param>
private void BindMixins(InternalEntityEntry entry, IEntityType entityType, object entity)
{
var mixinHost = entity as ISupportMixins;
if (mixinHost != null)
{
var mixinTypes = entityType
.Annotations
.Where(a => a.Name == "MixinType")
.Select(a => (Type)a.Value)
.Distinct()
.ToArray();
foreach (var mixinType in mixinTypes)
{
// Create the mixin.
var mixin = (Mixin)Activator.CreateInstance(mixinType);
// Set the resolver.
mixin.SetPropertyEntryResolver(p => new PropertyEntry(entry, p));
// Assign to the host entity.
mixinHost.AddMixin(mixin);
}
}
}
示例5: 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;
}
示例6: Select
/// <summary>
/// Selects the appropriate value generator for a given property.
/// </summary>
/// <param name="property"> The property to get the value generator for. </param>
/// <param name="entityType">
/// The entity type that the value generator will be used for. When called on inherited properties on derived entity types,
/// this entity type may be different from the declared entity type on <paramref name="property" />
/// </param>
/// <returns> The value generator to be used. </returns>
public virtual ValueGenerator Select(IProperty property, IEntityType entityType)
{
Check.NotNull(property, nameof(property));
Check.NotNull(entityType, nameof(entityType));
return Cache.GetOrAdd(property, entityType, Create);
}
示例7: Create
public override EntityKey Create(IEntityType entityType, IReadOnlyList<IProperty> properties, IPropertyBagEntry propertyBagEntry)
{
Check.NotNull(entityType, "entityType");
Check.NotNull(properties, "properties");
Check.NotNull(propertyBagEntry, "propertyBagEntry");
return Create(entityType, properties.Select(p => propertyBagEntry[p]).ToArray());
}
示例8: Create
/// <inheritdoc />
public override InternalEntityEntry Create(IStateManager stateManager, IEntityType entityType, object entity, ValueBuffer valueBuffer)
{
var entry = base.Create(stateManager, entityType, entity, valueBuffer);
BindMixins(entry, entityType, entity);
return entry;
}
示例9: GetOrAdd
/// <summary>
/// Gets the existing value generator from the cache, or creates a new one if one is not present in
/// the cache.
/// </summary>
/// <param name="property"> The property to get the value generator for. </param>
/// <param name="entityType">
/// The entity type that the value generator will be used for. When called on inherited properties on derived entity types,
/// this entity type may be different from the declared entity type on <paramref name="property" />
/// </param>
/// <param name="factory"> Factory to create a new value generator if one is not present in the cache. </param>
/// <returns> The existing or newly created value generator. </returns>
public virtual ValueGenerator GetOrAdd(
IProperty property, IEntityType entityType, Func<IProperty, IEntityType, ValueGenerator> factory)
{
Check.NotNull(property, nameof(property));
Check.NotNull(factory, nameof(factory));
return _cache.GetOrAdd(new CacheKey(property, entityType, factory), ck => ck.Factory(ck.Property, ck.EntityType));
}
示例10: CreateNewEntry
public virtual InternalEntityEntry CreateNewEntry(IEntityType entityType)
{
// TODO: Consider entities without parameterless constructor--use o/c mapping info?
// Issue #240
var entity = entityType.HasClrType() ? Activator.CreateInstance(entityType.ClrType) : null;
return _subscriber.SnapshotAndSubscribe(_factory.Create(this, entityType, entity), null);
}
示例11: CompositeEntityKey
public CompositeEntityKey([NotNull] IEntityType entityType, [NotNull] object[] keyValueParts)
{
Check.NotNull(entityType, "entityType");
Check.NotNull(keyValueParts, "keyValueParts");
_entityType = entityType;
_keyValueParts = keyValueParts;
}
示例12: Select
public override ValueGenerator Select(IProperty property, IEntityType entityType)
{
Check.NotNull(property, nameof(property));
Check.NotNull(entityType, nameof(entityType));
return property.SqlServer().IdentityStrategy == SqlServerIdentityStrategy.SequenceHiLo
? _sequenceFactory.Create(property, Cache.GetOrAddSequenceState(property), _connection)
: Cache.GetOrAdd(property, entityType, Create);
}
示例13: Create
public override ValueGenerator Create(IProperty property, IEntityType entityType)
{
Check.NotNull(property, nameof(property));
Check.NotNull(entityType, nameof(entityType));
return property.ClrType.IsInteger()
? _inMemoryFactory.Create(property)
: base.Create(property, entityType);
}
示例14: Create
public override ValueGenerator Create(IProperty property, IEntityType entityType)
{
Check.NotNull(property, nameof(property));
Check.NotNull(entityType, nameof(entityType));
return property.ClrType == typeof(Guid)
? _sequentialGuidFactory.Create(property)
: base.Create(property, entityType);
}
示例15: CreateMaterializeExpression
public virtual Expression CreateMaterializeExpression(
IEntityType entityType,
Expression valueReaderExpression,
int[] indexMap = null)
{
Check.NotNull(entityType, nameof(entityType));
Check.NotNull(valueReaderExpression, nameof(valueReaderExpression));
var materializer = entityType as IEntityMaterializer;
if (materializer != null)
{
return Expression.Call(
Expression.Constant(materializer),
((Func<IValueReader, object>)materializer.CreateEntity).GetMethodInfo(),
valueReaderExpression);
}
if (!entityType.HasClrType())
{
throw new InvalidOperationException(Strings.NoClrType(entityType.Name));
}
if (entityType.IsAbstract)
{
throw new InvalidOperationException(Strings.CannotMaterializeAbstractType(entityType));
}
var instanceVariable = Expression.Variable(entityType.ClrType, "instance");
var blockExpressions
= new List<Expression>
{
Expression.Assign(
instanceVariable,
Expression.New(entityType.ClrType.GetDeclaredConstructor(null)))
};
blockExpressions.AddRange(
from mapping in _memberMapper.MapPropertiesToMembers(entityType)
let propertyInfo = mapping.Item2 as PropertyInfo
let targetMember
= propertyInfo != null
? Expression.Property(instanceVariable, propertyInfo)
: Expression.Field(instanceVariable, (FieldInfo)mapping.Item2)
select
Expression.Assign(
targetMember,
CreateReadValueExpression(
valueReaderExpression,
targetMember.Type,
indexMap?[mapping.Item1.Index] ?? mapping.Item1.Index)));
blockExpressions.Add(instanceVariable);
return Expression.Block(new[] { instanceVariable }, blockExpressions);
}