I'm trying to initialze the CreatedAt and Guid value the first time a record is created via Entity Framework. But when performing an update using the same model, I don't want to overwrite that value. (As it is a timestamp for creation)
This is what I have currently:
public EntityBase()
{
if(this.CreatedAt == null)
this.CreatedAt = DateTimeOffset.Now;
this.UUId = new Guid();
this.UpdatedAt = DateTimeOffset.Now;
}
Whenever I create an instance of this model the constructor will be invoked and a new DateCreated value. Would this be a valid way?