本文整理汇总了C#中EntityEntry类的典型用法代码示例。如果您正苦于以下问题:C# EntityEntry类的具体用法?C# EntityEntry怎么用?C# EntityEntry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EntityEntry类属于命名空间,在下文中一共展示了EntityEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
/// <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 void Generate(InternalEntityEntry entry)
{
var entityEntry = new EntityEntry(entry);
foreach (var property in entry.EntityType.GetProperties())
{
var isForeignKey = property.IsForeignKey();
if ((property.RequiresValueGenerator || isForeignKey)
&& property.ClrType.IsDefaultValue(entry[property]))
{
if (isForeignKey)
{
_keyPropagator.PropagateValue(entry, property);
}
else
{
var valueGenerator = _valueGeneratorSelector.Select(property, property.IsKey()
? property.DeclaringEntityType
: entry.EntityType);
Debug.Assert(valueGenerator != null);
SetGeneratedValue(entry, property, valueGenerator.Next(entityEntry), valueGenerator.GeneratesTemporaryValues);
}
}
}
}
示例2: TakeSnapshot
// See IChangeTrackingStrategy documentation
public void TakeSnapshot(EntityEntry entry)
{
if (entry != null)
{
entry.TakeSnapshot(false);
}
}
示例3: CreateKeyFromForeignKeyValues
/// <summary>
/// Creates an EntityKey for a principal entity based on the foreign key values contained
/// in this entity. This implies that this entity is at the dependent end of the relationship.
/// </summary>
/// <param name="dependentEntry">The EntityEntry for the dependent that contains the FK</param>
/// <param name="relatedEnd">Identifies the principal end for which a key is required</param>
/// <returns>The key, or null if any value in the key is null</returns>
public static EntityKey CreateKeyFromForeignKeyValues(EntityEntry dependentEntry, RelatedEnd relatedEnd)
{
// Note: there is only ever one constraint per association type
ReferentialConstraint constraint = ((AssociationType)relatedEnd.RelationMetadata).ReferentialConstraints.First();
Debug.Assert(constraint.FromRole.Identity == relatedEnd.TargetRoleName, "Unexpected constraint role");
return CreateKeyFromForeignKeyValues(dependentEntry, constraint, relatedEnd.GetTargetEntitySetFromRelationshipSet(), useOriginalValues: false);
}
示例4: TakeSnapshot
// See IChangeTrackingStrategy documentation
public void TakeSnapshot(EntityEntry entry)
{
if (entry != null && entry.RequiresComplexChangeTracking)
{
entry.TakeSnapshot(true);
}
}
示例5: Adds_original_value_for_scalar_property_when_some_other_original_values_exist
public void Adds_original_value_for_scalar_property_when_some_other_original_values_exist()
{
var mockMemberMetadata1 = new Mock<StateManagerMemberMetadata>();
mockMemberMetadata1.Setup(m => m.IsComplex).Returns(false);
var mockMemberMetadata2 = new Mock<StateManagerMemberMetadata>();
mockMemberMetadata2.Setup(m => m.IsComplex).Returns(false);
var mockMetadata = new Mock<StateManagerTypeMetadata>();
mockMetadata.Setup(m => m.Member(1)).Returns(mockMemberMetadata1.Object);
mockMetadata.Setup(m => m.Member(2)).Returns(mockMemberMetadata2.Object);
var entry = new EntityEntry();
entry.SetOriginalEntityValue(mockMetadata.Object, 2, new object(), 7);
var userObject = new object();
var value = new object();
entry.SetOriginalEntityValue(mockMetadata.Object, 1, userObject, value);
Assert.Equal(1, entry.FindOriginalValueIndex(mockMemberMetadata1.Object, userObject));
Assert.Same(
value,
entry.GetOriginalEntityValue(mockMetadata.Object, 1, userObject, ObjectStateValueRecord.OriginalReadonly));
}
示例6: GetValues
private object[] GetValues(object entity, EntityEntry entry, EntityMode entityMode, bool mightBeDirty, ISessionImplementor session)
{
object[] loadedState = entry.LoadedState;
Status status = entry.Status;
IEntityPersister persister = entry.Persister;
object[] values;
if (status == Status.Deleted)
{
//grab its state saved at deletion
values = entry.DeletedState;
}
else if (!mightBeDirty && loadedState != null)
{
values = loadedState;
}
else
{
CheckId(entity, persister, entry.Id, entityMode);
// grab its current state
values = persister.GetPropertyValues(entity, entityMode);
CheckNaturalId(persister, entry, values, loadedState, entityMode, session);
}
return values;
}
示例7: GetErrors
private IEnumerable<DataValidationResult> GetErrors(DbEntityValidationException validationException)
{
foreach (var dbEntityValidationResult in validationException.EntityValidationErrors)
{
EntityEntry entry = new EntityEntry(dbEntityValidationResult.Entry);
IEnumerable<ValidationError> entryErrors = GetEntryErrors(dbEntityValidationResult.ValidationErrors);
yield return new DataValidationResult(entry, entryErrors);
}
}
示例8: UpgradeLock
/// <summary>
/// Performs a pessimistic lock upgrade on a given entity, if needed.
/// </summary>
/// <param name="entity">The entity for which to upgrade the lock.</param>
/// <param name="entry">The entity's EntityEntry instance.</param>
/// <param name="requestedLockMode">The lock mode being requested for locking. </param>
/// <param name="source">The session which is the source of the event being processed.</param>
protected virtual void UpgradeLock(object entity, EntityEntry entry, LockMode requestedLockMode, ISessionImplementor source)
{
if (requestedLockMode.GreaterThan(entry.LockMode))
{
// The user requested a "greater" (i.e. more restrictive) form of
// pessimistic lock
if (entry.Status != Status.Loaded)
{
throw new ObjectDeletedException("attempted to lock a deleted instance", entry.Id, entry.EntityName);
}
IEntityPersister persister = entry.Persister;
if (log.IsDebugEnabled)
{
log.Debug(string.Format("locking {0} in mode: {1}", MessageHelper.InfoString(persister, entry.Id, source.Factory), requestedLockMode));
}
ISoftLock slock;
CacheKey ck;
if (persister.HasCache)
{
ck = new CacheKey(entry.Id, persister.IdentifierType, persister.RootEntityName, source.EntityMode, source.Factory);
slock = persister.Cache.Lock(ck, entry.Version);
}
else
{
ck = null;
slock = null;
}
try
{
if (persister.IsVersioned && requestedLockMode == LockMode.Force)
{
// todo : should we check the current isolation mode explicitly?
object nextVersion = persister.ForceVersionIncrement(entry.Id, entry.Version, source);
entry.ForceLocked(entity, nextVersion);
}
else
{
persister.Lock(entry.Id, entry.Version, entity, requestedLockMode, source);
}
entry.LockMode = requestedLockMode;
}
finally
{
// the database now holds a lock + the object is flushed from the cache,
// so release the soft lock
if (persister.HasCache)
{
persister.Cache.Release(ck, slock);
}
}
}
}
示例9: UpdateCurrentValueRecord
// See IChangeTrackingStrategy documentation
public void UpdateCurrentValueRecord(object value, EntityEntry entry)
{
// Has change tracker, but may or may not be a proxy
bool isProxy = entry.WrappedEntity.IdentityType != _entity.GetType();
entry.UpdateRecordWithoutSetModified(value, entry.CurrentValues);
if (isProxy)
{
entry.DetectChangesInProperties(true); // detect only complex property changes
}
}
示例10: Map
public void Map(EntityEntry entityEntry, EntityEntry auditEntry)
{
foreach (var propMap in PropertyMap.Values)
{
try
{
var originalValue = entityEntry.Property(propMap.EntityProperty.Name).OriginalValue;
auditEntry.Property(propMap.AuditProperty.Name).CurrentValue = originalValue;
}
catch (Exception)
{
// Ignoring
}
}
auditEntry.Property("ChangeType").CurrentValue = _changeTypeMap[entityEntry.State];
}
示例11: ObjectStateEntryDbUpdatableDataRecord
internal ObjectStateEntryDbUpdatableDataRecord(EntityEntry cacheEntry, StateManagerTypeMetadata metadata, object userObject)
: base(cacheEntry, metadata, userObject)
{
EntityUtil.CheckArgumentNull(cacheEntry, "cacheEntry");
EntityUtil.CheckArgumentNull(userObject, "userObject");
EntityUtil.CheckArgumentNull(metadata, "metadata");
Debug.Assert(!cacheEntry.IsKeyEntry, "Cannot create an ObjectStateEntryDbUpdatableDataRecord for a key entry");
switch (cacheEntry.State)
{
case EntityState.Unchanged:
case EntityState.Modified:
case EntityState.Added:
break;
default:
Debug.Assert(false, "A CurrentValueRecord cannot be created for an entity object that is in a deleted or detached state.");
break;
}
}
示例12: ObjectStateEntryDbUpdatableDataRecord
internal ObjectStateEntryDbUpdatableDataRecord(EntityEntry cacheEntry, StateManagerTypeMetadata metadata, object userObject)
: base(cacheEntry, metadata, userObject)
{
//Contract.Requires(cacheEntry != null);
//Contract.Requires(userObject != null);
//Contract.Requires(metadata != null);
Debug.Assert(!cacheEntry.IsKeyEntry, "Cannot create an ObjectStateEntryDbUpdatableDataRecord for a key entry");
switch (cacheEntry.State)
{
case EntityState.Unchanged:
case EntityState.Modified:
case EntityState.Added:
break;
default:
Debug.Assert(
false, "A CurrentValueRecord cannot be created for an entity object that is in a deleted or detached state.");
break;
}
}
示例13: TraverseGraph
public virtual IEnumerable<EntityEntry> TraverseGraph(object entity)
{
var entry = new EntityEntry(_context, _stateManager.GetOrCreateEntry(entity));
if (entry.State != EntityState.Detached)
{
yield break;
}
yield return entry;
if (entry.State != EntityState.Detached)
{
var internalEntry = ((IAccessor<InternalEntityEntry>)entry).Service;
var navigations = internalEntry.EntityType.GetNavigations();
foreach (var navigation in navigations)
{
var navigationValue = internalEntry[navigation];
if (navigationValue != null)
{
if (navigation.IsCollection())
{
foreach (var relatedEntity in (IEnumerable)navigationValue)
{
foreach (var relatedEntry in TraverseGraph(relatedEntity))
{
yield return relatedEntry;
}
}
}
else
{
foreach (var relatedEntry in TraverseGraph(navigationValue))
{
yield return relatedEntry;
}
}
}
}
}
}
示例14: SetCurrentValue
// See IChangeTrackingStrategy documentation
public void SetCurrentValue(EntityEntry entry, StateManagerMemberMetadata member, int ordinal, object target, object value)
{
// If the target is the entity, then this is a change to a member on the entity itself rather than
// a change to some complex type property defined on the entity. In this case we can use the change tracking
// API in the normal way.
if (ReferenceEquals(target, entry.Entity))
{
// equivalent of EntityObject.ReportPropertyChanging()
((IEntityChangeTracker)entry).EntityMemberChanging(member.CLayerName);
member.SetValue(target, value);
// equivalent of EntityObject.ReportPropertyChanged()
((IEntityChangeTracker)entry).EntityMemberChanged(member.CLayerName);
if (member.IsComplex)
{
// This is required because the OSE contains a separate cache of user objects for
// complex objects such that original values can be looked up correctly.
entry.UpdateComplexObjectSnapshot(member, target, ordinal, value);
}
}
else
{
// Must be a complex type. We would like to do this:
// ((IEntityChangeTracker)entry).EntityComplexMemberChanging(topLevelMember.CLayerName, target, member.CLayerName);
// ((IEntityChangeTracker)entry).EntityComplexMemberChanged(topLevelMember.CLayerName, target, member.CLayerName);
//
// However, we have no way of getting the topLevelMember.CLayerName. This is because the value record does not
// contain any reference to its parent. (In non-POCO, ComplexObject takes care of this.)
// Therefore, in this case we are going to just call a localized DetectChanges to make sure that changes in the
// complex types are found.
//
// Note that this case only happens when the entity is POCO and complex types are set through the CurrentValues
// object. This is probably not a very common pattern.
member.SetValue(target, value);
if (entry.State
!= EntityState.Added)
{
// Entry is not Detached - checked in ValidateState() in EntityEntry.SetCurrentEntityValue
entry.DetectChangesInProperties(true);
}
}
}
示例15: ObjectStateEntryOriginalDbUpdatableDataRecord_Internal
internal ObjectStateEntryOriginalDbUpdatableDataRecord_Internal(
EntityEntry cacheEntry, StateManagerTypeMetadata metadata, object userObject)
: base(cacheEntry, metadata, userObject)
{
DebugCheck.NotNull(cacheEntry);
DebugCheck.NotNull(userObject);
DebugCheck.NotNull(metadata);
Debug.Assert(!cacheEntry.IsKeyEntry, "Cannot create an ObjectStateEntryOriginalDbUpdatableDataRecord_Internal for a key entry");
switch (cacheEntry.State)
{
case EntityState.Unchanged:
case EntityState.Modified:
case EntityState.Deleted:
break;
default:
Debug.Assert(false, "An OriginalValueRecord cannot be created for an object in an added or detached state.");
break;
}
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:20,代码来源:ObjectStateEntryOriginalDbUpdatableDataRecord_Internal.cs