I have a base class like below. All my entities inherit from this
public abstract Entity
{
public DataTime CreationDate{get;set;}
public DataTime ModifiedDate{get;set;}
}
I want to set the CreationDate
when new entity is added to the database.
By overriding SaveChanges()
method and checking EntityState
is in Modified
state I can set the ModifiedDate
.
The problem is I can not identify whether it is a new entity or not by checking the EntityState
because new entities and other loaded entities are in Added
state.
So is there a way to differentiate new entities?
thanks in advance.