I am developing an mvc application and I am using fluent nhibernate and enverse to store information in db and to auditing my data.
My base class for entities looks like:
[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; }
}
My fluent mapping:
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);
}
}
When I store each entity to db then action on pre insert is running and it sets values for createdDate and createdBy.
I have a problem when i am updating an entity. CreatedDate and CreatedBY are not update fields so I don't store this information in my viewmodel so during conversion to model/entity a have no information about createdDate and createdBy. In my table I have all information after edit and entitybase but in auditing I receive a new row with empty CratedDate and CreatedBy.
is there any way to configure enverse to not lose this data?