本文整理汇总了C#中EntityState.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# EntityState.ToString方法的具体用法?C# EntityState.ToString怎么用?C# EntityState.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityState
的用法示例。
在下文中一共展示了EntityState.ToString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FlightVersionHistory
/// <summary>
/// Initializes a new instance of the <see cref="FlightVersionHistory"/> class.
/// </summary>
/// <param name="flight">
/// The flight.
/// </param>
/// <param name="entityState">
/// The entity state.
/// </param>
public FlightVersionHistory(Flight f, EntityState entityState)
{
this.State = entityState.ToString();
this.FlightId = f.FlightId;
this.Created = DateTime.Now;
this.Deleted = f.Deleted;
this.LastUpdated = f.LastUpdated;
this.LastUpdatedBy = f.LastUpdatedBy;
this.Description = f.Description;
this.Date = f.Date;
this.Departure = f.Departure;
this.Landing = f.Landing;
this.LandingCount = f.LandingCount;
this.PlaneId = f.PlaneId;
this.PilotId = f.PilotId;
this.PilotBackseatId = f.PilotBackseatId;
this.BetalerId = f.BetalerId;
this.StartTypeId = f.StartTypeId;
this.StartedFromId = f.StartedFromId;
this.LandedOnId = f.LandedOnId;
this.TachoDeparture = f.TachoDeparture;
this.TachoLanding = f.TachoLanding;
}
示例2: GetAuditLogs
private static IEnumerable<CustomAuditLog> GetAuditLogs(EntityEntry entityEntry, string userName, EntityState entityState)
{
var returnValue = new List<CustomAuditLog>();
// var keyRepresentation = BuildKeyRepresentation(entityEntry, KeySeperator);
DateTime RightNow = DateTime.Now;
Guid AuditBatchID;
UuidCreateSequential(out AuditBatchID);
var auditedPropertyNames =
entityEntry.Entity.GetType()
.GetProperties().Where(p => !p.GetCustomAttributes(typeof(DoNotAudit), true).Any())
.Select(info => info.Name);
var differences = new List<PropertyDiff>();
foreach (var propertyEntry in entityEntry.Metadata.GetProperties()
.Where(x => auditedPropertyNames.Contains(x.Name))
.Select(property => new { PropertyName = property.Name, Property = entityEntry.Property(property.Name) }))
{
var originalValue = Convert.ToString(propertyEntry.Property.OriginalValue);
var currentValue = Convert.ToString(propertyEntry.Property.CurrentValue);
if (entityState == EntityState.Modified && originalValue == currentValue) //Values are the same, don't log
continue;
var diff = new PropertyDiff { PropertyName = propertyEntry.PropertyName, OriginalValue = originalValue, NewValue = currentValue } ;
differences.Add(diff);
}
var ser = JsonConvert.SerializeObject(differences);
returnValue.Add(new CustomAuditLog
{
Differences = ser,
EventDateTime = RightNow,
EventType = entityState.ToString(),
UserName = userName,
TableName = entityEntry.Entity.GetType().Name
});
return returnValue;
}
示例3: GetAuditLogs
private static IEnumerable<AuditLog> GetAuditLogs(EntityEntry entityEntry, string userName, EntityState entityState)
{
var returnValue = new List<AuditLog>();
var keyRepresentation = BuildKeyRepresentation(entityEntry, KeySeperator);
var auditedPropertyNames =
entityEntry.Entity.GetType()
.GetProperties().Where(p => !p.GetCustomAttributes(typeof (DoNotAudit), true).Any())
.Select(info => info.Name);
foreach (var propertyEntry in entityEntry.Metadata.GetProperties()
.Where(x => auditedPropertyNames.Contains(x.Name))
.Select(property => entityEntry.Property(property.Name)))
{
if(entityState == EntityState.Modified)
if (Convert.ToString(propertyEntry.OriginalValue) == Convert.ToString(propertyEntry.CurrentValue)) //Values are the same, don't log
continue;
returnValue.Add(new AuditLog
{
KeyNames = keyRepresentation.Key,
KeyValues = keyRepresentation.Value,
OriginalValue = entityState != EntityState.Added
? Convert.ToString(propertyEntry.OriginalValue)
: null,
NewValue = entityState == EntityState.Modified || entityState == EntityState.Added
? Convert.ToString(propertyEntry.CurrentValue)
: null,
ColumnName = propertyEntry.Metadata.Name,
EventDateTime = DateTime.Now,
EventType = entityState.ToString(),
UserName = userName,
TableName = entityEntry.Entity.GetType().Name
});
}
return returnValue;
}
示例4: GetAuditLogs
private static IEnumerable<AuditLog> GetAuditLogs(DbEntityEntry entityEntry, string userName, EntityState entityState, ObjectContext objectContext,
DateTime auditDateTime)
{
var returnValue = new List<AuditLog>();
var keyRepresentation = BuildKeyRepresentation(entityEntry, KeySeperator, objectContext);
var auditedPropertyNames = GetDeclaredPropertyNames(entityEntry.Entity.GetType(), objectContext.MetadataWorkspace);
foreach (var propertyName in auditedPropertyNames)
{
var currentValue = Convert.ToString(entityEntry.CurrentValues.GetValue<object>(propertyName));
var originalValue = Convert.ToString(entityEntry.GetDatabaseValues().GetValue<object>(propertyName));
if (entityState == EntityState.Modified)
if (originalValue == currentValue) //Values are the same, don't log
continue;
returnValue.Add(new AuditLog
{
KeyNames = keyRepresentation.Key,
KeyValues = keyRepresentation.Value,
OriginalValue = entityState != EntityState.Added
? originalValue
: null,
NewValue = entityState == EntityState.Modified || entityState == EntityState.Added
? currentValue
: null,
ColumnName = propertyName,
EventDateTime = auditDateTime,
EventType = entityState.ToString(),
UserName = userName,
TableName = entityEntry.Entity.GetType().Name
});
}
return returnValue;
}
示例5: StateEntry2OperationLog
/// <summary>
/// States the entry2 operation log.
/// </summary>
/// <param name="objectType">Type of the object.</param>
/// <param name="createdDate">The createdDate.</param>
/// <param name="objectId">The key value.</param>
/// <param name="state">The state.</param>
/// <returns>
/// OperationLog object
/// </returns>
private OperationLogEntity StateEntry2OperationLog(string objectType, DateTime createdDate, string objectId, EntityState state)
{
var retVal = new OperationLogEntity
{
Id = Guid.NewGuid().ToString("N"),
CreatedDate = createdDate,
ObjectId = objectId,
ObjectType = objectType,
CreatedBy = CurrentPrincipal.GetCurrentUserName(),
OperationType = state.ToString()
};
return retVal;
}
示例6: VerifyData
public static void VerifyData(Workspace w, Hashtable entities, Hashtable entitiesAfter)
{
IDictionaryEnumerator _enum = entities.GetEnumerator();
object _entity = null;
EntityStates _state = EntityStates.Unchanged;
string _uri = null;
while (_enum.MoveNext())
{
_entity = _enum.Key;
_state = (EntityStates)Enum.Parse(typeof(EntityStates), (string)((string[])_enum.Value)[0], true);
switch (_state)
{
case EntityStates.Added:
if (entitiesAfter != null)
{
_uri = (string)((string[])entitiesAfter[_entity])[1];
Verify(_entity, _uri, _state, w);
AstoriaTestLog.WriteLineIgnore("Verified entity " + _entity.GetType().Name + " was inserted!");
}
break;
case EntityStates.Unchanged:
case EntityStates.Modified:
_uri = (string)((string[])_enum.Value)[1];
Verify(_entity, _uri, _state, w);
AstoriaTestLog.WriteLineIgnore("Verified entity " + _entity.GetType().Name + " was " + _state.ToString().ToLower());
break;
case EntityStates.Deleted:
try
{
_uri = (string)((string[])_enum.Value)[1];
Verify(_entity, _uri, _state, w);
}
catch (Exception e)
{
if (e.InnerException is DataServiceQueryException)
AstoriaTestLog.WriteLineIgnore("Verified entity " + _entity.GetType().Name + " was " + _state.ToString().ToLower());
else
AstoriaTestLog.FailAndContinue(e);
}
break;
}
}
}
示例7: StateEntry2OperationLog
/// <summary>
/// States the entry2 operation log.
/// </summary>
/// <param name="objectType">Type of the object.</param>
/// <param name="createdDate">The createdDate.</param>
/// <param name="objectId">The key value.</param>
/// <param name="state">The state.</param>
/// <returns>
/// OperationLog object
/// </returns>
private OperationLogEntity StateEntry2OperationLog(string objectType, DateTime createdDate, string objectId, EntityState state)
{
var retVal = new OperationLogEntity
{
ObjectId = objectId,
ObjectType = objectType,
OperationType = state.ToString()
};
return retVal;
}