I have an entity like this. Let's say that name is the only :
public class MyEntity
{
public Guid Id { get; set; } // immutable
public string Name { get; set; } // can be changed
// These are not exposed on the domain layer. They're just bookkeeping fields.
public string CreatedBy { get; set; }
public DateTime DateCreated { get; set; }
public string UpdatedBy { get; set; }
public DateTime DateUpdated { get; set; }
}
If I populate the 2 "updated" fields before calling SaveChanges(), my entity will be erroneously marked changed if Name hasn't changed. Therefore, I need an event on the DbContext to hook into in order to populate those 2 fields just before committing the unit of work, but only on entities that have actually changed.
Does such an event exist? Can nHibernate do this?