本文整理汇总了C#中System.Data.Objects.ObjectStateEntry类的典型用法代码示例。如果您正苦于以下问题:C# ObjectStateEntry类的具体用法?C# ObjectStateEntry怎么用?C# ObjectStateEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectStateEntry类属于System.Data.Objects命名空间,在下文中一共展示了ObjectStateEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsTargetEntity
public virtual bool IsTargetEntity(ObjectStateEntry item)
{
return item.State != EntityState.Detached &&
TargetType.IsInstanceOfType(item.Entity);
}
示例2: GetIdentifierValue
/// <summary>
/// Gets the identifier value for the entity in the ObjectStateEntry.
/// </summary>
/// <param name="objectStateEntry">The ObjectStateEntry.</param>
/// <returns>The identifier value.</returns>
/// <remarks>
/// When auditing Adds, this needs to be called AFTER SaveChanges, or else it will return null.
/// </remarks>
public static string GetIdentifierValue(ObjectStateEntry objectStateEntry)
{
if (objectStateEntry == null)
{
throw new ArgumentNullException("objectStateEntry");
}
string id = null;
var entityKey = objectStateEntry.EntityKey;
if (entityKey != null)
{
var keyValues = entityKey.EntityKeyValues;
if (keyValues != null)
{
if (keyValues.Length == 1)
{
id = keyValues[0].Value.ToString();
}
else if (keyValues.Length > 1)
{
id = string.Join(_composikeKeySeparator, keyValues.OrderBy(k => k.Key).Select(k => k.Value.ToString()).ToArray());
}
}
}
return id;
}
示例3: TrackOriginalValue
/// <summary>
/// Tracks the original value.
/// </summary>
/// <param name="objectStateEntry">The object state entry.</param>
private void TrackOriginalValue(ObjectStateEntry objectStateEntry)
{
object propertyValue = objectStateEntry.OriginalValues[PropertyName];
if (propertyValue != null)
{
OriginalValue = propertyValue.ToString();
}
}
示例4: TrackNewValue
/// <summary>
/// Tracks the new value.
/// </summary>
/// <param name="objectStateEntry">The object state entry.</param>
private void TrackNewValue(ObjectStateEntry objectStateEntry)
{
object propertyValue = objectStateEntry.CurrentValues[PropertyName];
if (propertyValue != null)
{
NewValue = propertyValue.ToString();
}
}
示例5: GetUpdatedEntityValues
private static IEnumerable<Tuple<string, object, object>> GetUpdatedEntityValues(ObjectStateEntry entry)
{
foreach (string propname in entry.GetModifiedProperties())
{
object newval = entry.CurrentValues[propname];
object oldval = entry.OriginalValues[propname];
yield return Tuple.Create(propname, newval, oldval);
}
}
示例6: TrackDelete
/// <summary>
/// Tracks the delete.
/// </summary>
/// <param name="objectStateEntry">The object state entry.</param>
public void TrackDelete(ObjectStateEntry objectStateEntry)
{
if (objectStateEntry == null)
{
throw new ArgumentNullException("objectStateEntry");
}
AuditEntities.Add(new EntityDeletedAudit(objectStateEntry));
RemoveReads();
}
示例7: TrackingAuditEntity
public TrackingAuditEntity(ObjectStateEntry objectStateEntry, AuditEntityAction action)
{
if (objectStateEntry == null)
{
throw new ArgumentNullException("objectStateEntry");
}
EntityType = EntityTypeResolver.ResolveActualEntityType(objectStateEntry.Entity).Name;
EntityIdentifier = IdentifierUtility.GetIdentifierValue(objectStateEntry);
AuditEntityAction = action;
AuditEntityProperties = new Collection<AuditEntityProperty>();
}
示例8: GetAddedEntityValues
private static IEnumerable<Tuple<string, object, object>> GetAddedEntityValues(ObjectStateEntry entry)
{
foreach (var propinfo in entry.CurrentValues.DataRecordInfo.FieldMetadata)
{
object newval = entry.CurrentValues[propinfo.FieldType.Name];
if (newval.GetType() == typeof(EntityKey))
{
newval = ((EntityKey)newval).EntityKeyValues.Select(k => k.Value).FirstOrDefault();
}
yield return Tuple.Create(propinfo.FieldType.Name, newval, (object)null);
}
}
示例9: TrackProperties
/// <summary>
/// Tracks the properties.
/// </summary>
/// <param name="objectStateEntry">The object state entry.</param>
protected void TrackProperties(ObjectStateEntry objectStateEntry)
{
var currentValues = objectStateEntry.CurrentValues;
for (int ordinal = 0; ordinal < currentValues.FieldCount; ordinal++)
{
var propertyName = currentValues.GetName(ordinal);
if (!IsStoreGenerated(propertyName, objectStateEntry))
{
AuditEntityProperties.Add(new TrackingAuditEntityProperty(propertyName, objectStateEntry));
}
}
}
示例10: GetAction
private static AuditAction GetAction(ObjectStateEntry entity)
{
switch (entity.State)
{
case EntityState.Added:
return AuditAction.Added;
case EntityState.Deleted:
return AuditAction.Deleted;
default:
return AuditAction.Modified;
}
}
示例11: TrackProperties
/// <summary>
/// Tracks the properties.
/// </summary>
/// <param name="objectStateEntry">The object state entry.</param>
protected void TrackProperties(ObjectStateEntry objectStateEntry)
{
foreach (string propertyName in objectStateEntry.GetModifiedProperties())
{
if (!IsStoreGenerated(propertyName, objectStateEntry))
{
var auditProperty = new TrackingAuditEntityProperty(propertyName, objectStateEntry);
if (auditProperty.HasChanges)
{
AuditEntityProperties.Add(auditProperty);
}
}
}
}
示例12: ObjectStateEntryDbDataRecord
internal ObjectStateEntryDbDataRecord(RelationshipEntry cacheEntry)
{
EntityUtil.CheckArgumentNull(cacheEntry, "cacheEntry");
Debug.Assert(!cacheEntry.IsKeyEntry, "Cannot create an ObjectStateEntryDbDataRecord for a key entry");
switch (cacheEntry.State)
{
case EntityState.Unchanged:
case EntityState.Modified:
case EntityState.Deleted:
_cacheEntry = cacheEntry;
break;
default:
Debug.Assert(false, "A DbDataRecord cannot be created for an entity object that is in an added or detached state.");
break;
}
}
示例13: TrackingAuditEntityProperty
/// <summary>
/// Initializes a new instance of the <see cref="TrackingAuditEntityProperty"/> class.
/// </summary>
/// <param name="propertyName">Name of the property.</param>
/// <param name="objectStateEntry">The object state entry.</param>
public TrackingAuditEntityProperty(string propertyName, ObjectStateEntry objectStateEntry)
{
if (objectStateEntry == null)
{
throw new ArgumentNullException("objectStateEntry");
}
if (string.IsNullOrEmpty(propertyName))
{
throw new ArgumentNullException("propertyName");
}
PropertyName = propertyName;
TrackNewValue(objectStateEntry);
if (objectStateEntry.State == EntityState.Modified)
{
TrackOriginalValue(objectStateEntry);
}
}
示例14: ValidateBelongsTo
static void ValidateBelongsTo(this AssociationEndMember end, ObjectStateEntry entry)
{
if (!entry.IsRelationship)
{
throw new ArgumentException("is not a relationship entry", "entry");
}
var fieldMetadata =
entry.UsableValues().DataRecordInfo.FieldMetadata;
if (fieldMetadata[0].FieldType as AssociationEndMember != end &&
fieldMetadata[1].FieldType as AssociationEndMember != end)
{
throw new InvalidOperationException(string.Format(
"association end {0} does not participate in the " +
"relationship {1}", end, entry));
}
}
示例15: ObjectStateEntryDbDataRecord
internal ObjectStateEntryDbDataRecord(EntityEntry cacheEntry, StateManagerTypeMetadata metadata, object userObject)
{
//Contract.Requires(cacheEntry != null);
//Contract.Requires(userObject != null);
//Contract.Requires(metadata != null);
Debug.Assert(!cacheEntry.IsKeyEntry, "Cannot create an ObjectStateEntryDbDataRecord for a key entry");
switch (cacheEntry.State)
{
case EntityState.Unchanged:
case EntityState.Modified:
case EntityState.Deleted:
_cacheEntry = cacheEntry;
_userObject = userObject;
_metadata = metadata;
break;
default:
Debug.Assert(false, "A DbDataRecord cannot be created for an entity object that is in an added or detached state.");
break;
}
}