本文整理汇总了C#中DbEntityEntry.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# DbEntityEntry.Cast方法的具体用法?C# DbEntityEntry.Cast怎么用?C# DbEntityEntry.Cast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbEntityEntry
的用法示例。
在下文中一共展示了DbEntityEntry.Cast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnInsert
public void OnInsert(DbEntityEntry entityEntry)
{
if (entityEntry.Entity is EntityWithCreatedDate)
entityEntry.Cast<EntityWithCreatedDate>().Entity.Created = DateTime.Now;
if (entityEntry.Entity is Entity)
entityEntry.Cast<Entity>().Entity.Modified = DateTime.Now;
}
示例2: SetCreationAuditProperties
private void SetCreationAuditProperties(DbEntityEntry entry)
{
if (entry.Entity is IHasCreationTime)
{
entry.Cast<IHasCreationTime>().Entity.CreationTime = DateTime.Now; //TODO: UtcNow?
}
if (entry.Entity is ICreationAudited)
{
entry.Cast<ICreationAudited>().Entity.CreatorUserId = AbpSession.UserId;
}
}
示例3: HandleSoftDelete
private static void HandleSoftDelete(DbEntityEntry entry)
{
if (entry.Entity is ISoftDelete)
{
entry.State = EntityState.Unchanged;
entry.Cast<ISoftDelete>().Entity.IsDeleted = true;
}
}
示例4: SetModificationAuditProperties
private void SetModificationAuditProperties(DbEntityEntry entry)
{
if (entry.Entity is IModificationAudited)
{
var auditedEntry = entry.Cast<IModificationAudited>();
auditedEntry.Entity.LastModificationTime = DateTime.Now; //TODO: UtcNow?
auditedEntry.Entity.LastModifierUserId = AbpSession.UserId;
}
}
示例5: SetModificationAuditProperties
/// <summary>
/// The set modification audit properties.
/// </summary>
/// <param name="entry">
/// The entry.
/// </param>
protected virtual void SetModificationAuditProperties(DbEntityEntry entry)
{
if (!(entry.Entity is IModificationAudited))
{
return;
}
entry.Cast<IModificationAudited>().Entity.LastModificationTime = DateTime.Now;
if (this.workContext != null && !string.IsNullOrEmpty(this.workContext.CurrentCustomerId))
{
entry.Cast<IModificationAudited>().Entity.LastModifierUserId = Guid.Parse(this.workContext.CurrentCustomerId);
}
}
示例6: SetCreationAuditProperties
protected virtual void SetCreationAuditProperties(DbEntityEntry entry)
{
if (entry.Entity is IHasCreationTime)
{
entry.Cast<IHasCreationTime>().Entity.CreationTime = Clock.Now;
}
if (entry.Entity is ICreationAudited)
{
entry.Cast<ICreationAudited>().Entity.CreatorUserId = AbpSession.UserId;
}
}
示例7: CheckMayHaveTenant
protected virtual void CheckMayHaveTenant(DbEntityEntry entry)
{
if (!this.IsFilterEnabled(AbpDataFilters.MayHaveTenant))
{
return;
}
var currentTenantId = (int?)this.GetFilterParameterValue(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId);
var entity = entry.Cast<IMayHaveTenant>().Entity;
if (entity.TenantId != currentTenantId && entity.TenantId != AbpSession.TenantId)
{
throw new DbEntityValidationException("Can not set TenantId to a different value than the current filter parameter value or IAbpSession.TenantId while MayHaveTenant filter is enabled!");
}
}
示例8: CheckAndSetMustHaveTenant
protected virtual void CheckAndSetMustHaveTenant(DbEntityEntry entry)
{
var entity = entry.Cast<IMustHaveTenant>().Entity;
if (!this.IsFilterEnabled(AbpDataFilters.MustHaveTenant))
{
if (AbpSession.TenantId != null && entity.TenantId == 0)
{
entity.TenantId = AbpSession.GetTenantId();
}
return;
}
var currentTenantId = (int)this.GetFilterParameterValue(AbpDataFilters.MustHaveTenant, AbpDataFilters.Parameters.TenantId);
if (currentTenantId == 0)
{
throw new DbEntityValidationException("Can not save a IMustHaveTenant entity while MustHaveTenant filter is enabled and current filter parameter value is not set (Probably, no tenant user logged in)!");
}
if (entity.TenantId == 0)
{
entity.TenantId = currentTenantId;
}
else if (entity.TenantId != currentTenantId && entity.TenantId != AbpSession.TenantId)
{
throw new DbEntityValidationException("Can not set IMustHaveTenant.TenantId to a different value than the current filter parameter value or IAbpSession.TenantId while MustHaveTenant filter is enabled!");
}
}
示例9: CheckMayHaveTenant
protected virtual void CheckMayHaveTenant(DbEntityEntry entry)
{
if (!this.IsFilterEnabled(OwDataFilters.MayHaveTenant))
{
return;
}
var currentTenantId = (int?)this.GetFilterParameterValue(OwDataFilters.MayHaveTenant, OwDataFilters.Parameters.TenantId);
var entity = entry.Cast<IMayHaveTenant>().Entity;
if (entity.TenantId != currentTenantId && entity.TenantId != OwSession.TenantId)
{
throw new DbEntityValidationException("Can not set TenantId to a different value than the current filter parameter value or IOwSession.TenantId while MayHaveTenant filter is enabled!");
//不能TenantId设置为不同的值比当前的过滤参数值或IOwSession。TenantId虽然MayHaveTenant启用过滤器!
}
}
示例10: SetModificationAuditProperties
protected virtual void SetModificationAuditProperties(DbEntityEntry entry, long? userId)
{
if (entry.Entity is IHasModificationTime)
{
entry.Cast<IHasModificationTime>().Entity.LastModificationTime = Clock.Now;
}
if (entry.Entity is IModificationAudited)
{
var entity = entry.Cast<IModificationAudited>().Entity;
if (userId == null)
{
entity.LastModifierUserId = null;
return;
}
//Special check for multi-tenant entities
if (entity is IMayHaveTenant || entity is IMustHaveTenant)
{
//Sets LastModifierUserId only if current user is in same tenant/host with the given entity
if ((entity is IMayHaveTenant && entity.As<IMayHaveTenant>().TenantId == AbpSession.TenantId) ||
(entity is IMustHaveTenant && entity.As<IMustHaveTenant>().TenantId == AbpSession.TenantId))
{
entity.LastModifierUserId = userId;
}
else
{
entity.LastModifierUserId = null;
}
}
else
{
entity.LastModifierUserId = userId;
}
}
}
示例11: HandleSoftDelete
protected virtual void HandleSoftDelete(DbEntityEntry entry)
{
if (!(entry.Entity is ISoftDelete))
{
return;
}
var softDeleteEntry = entry.Cast<ISoftDelete>();
softDeleteEntry.State = EntityState.Unchanged;
softDeleteEntry.Entity.IsDeleted = true;
if (entry.Entity is IDeletionAudited<Guid>)
{
SetDeletionAuditProperties(entry.Cast<IDeletionAudited<Guid>>().Entity);
}
}
示例12: SetModificationAuditProperties
protected virtual void SetModificationAuditProperties(DbEntityEntry entry)
{
if (entry.Entity is IModificationAudited)
{
var auditedEntry = entry.Cast<IModificationAudited>();
auditedEntry.Entity.UpdateTime = ClockManager.Now;
auditedEntry.Entity.UpdateUserId = QdfSession.UserId;
}
}
示例13: OnUpdate
public void OnUpdate(DbEntityEntry entityEntry)
{
if (entityEntry.Entity is Entity)
entityEntry.Cast<Entity>().Entity.Modified = DateTime.Now;
}
示例14: SetModificationAuditProperties
/// <summary>
/// The set modification audit properties.
/// </summary>
/// <param name="entry">
/// The entry.
/// </param>
protected virtual void SetModificationAuditProperties(DbEntityEntry entry)
{
if (entry.Entity is IModificationAudited)
{
var auditedEntry = entry.Cast<IModificationAudited>();
var userid = Guid.Parse(this.WorkContext.CurrentCustomerId);
auditedEntry.Entity.LastModificationTime = DateTime.Now;
auditedEntry.Entity.LastModifierUserId = userid;
}
}
示例15: SetCreationAuditProperties
/// <summary>
/// The set creation audit properties.
/// </summary>
/// <param name="entry">
/// The entry.
/// </param>
protected virtual void SetCreationAuditProperties(DbEntityEntry entry)
{
if (entry.Entity is IHasCreationTime)
{
entry.Cast<IHasCreationTime>().Entity.CreationTime = DateTime.Now; // Clock.Now;
}
if (entry.Entity is ICreationAudited)
{
var userid = Guid.Parse(this.WorkContext.CurrentCustomerId);
entry.Cast<ICreationAudited>().Entity.CreatorUserId = userid;
}
}