我正在开发一个 mvc 应用程序,我正在使用流利的 nhibernate 和 enverse 将信息存储在 db 中并审核我的数据。
我的实体基类如下所示:
[Audited]
public class EntityBase : IEntity
{
public virtual int ID { get; set; }
public virtual string CreatedBy { get; set; }
public virtual string ModifiedBy { get; set; }
public virtual DateTime CreatedDate { get; set; }
public virtual DateTime? ModifiedDate { get; set; }
public virtual bool IsActive { get; set; }
}
我流利的映射:
internal class EntityMap<T> : ClassMap<T> where T:EntityBase
{
public EntityMap(string tableName = null)
{
Id(x => x.ID).DefaultStrategy<T>(tableName);
if (!string.IsNullOrEmpty(tableName))
base.Table(tableName);
Map(x => x.IsActive).Not.Nullable();
Map(x => x.CreatedDate).Not.Nullable().Not.Update().CustomType("Timestamp");
Map(x => x.CreatedBy).Not.Update();
Map(x => x.ModifiedDate).CustomType("Timestamp");
Map(x => x.ModifiedBy);
}
}
当我将每个实体存储到数据库时,预插入操作正在运行,它为 createdDate 和 createdBy 设置值。
我在更新实体时遇到问题。CreatedDate 和 CreatedBY 不是更新字段,因此我不会将此信息存储在我的视图模型中,因此在转换为模型/实体期间,没有关于 createdDate 和 createdBy 的信息。在我的表中,我拥有编辑和实体库之后的所有信息,但在审核中,我收到了一个新行,其中 CratedDate 和 CreatedBy 为空。
有什么方法可以配置逆向不丢失这些数据?