Using Entity Framework Set DateCreated on a poco object when saving -


I'm evaluating the unit framework 4.0 and I'm thinking how I can access entities before being saved to set the date date.

With NHibernate it can be done using a listener, if it helps?

You use ObjectContext event saving changelog Those who have the state EntityState.Added , retrieve those entities, and set DateCreated for those objects. To facilitate more agnostic handlers and avoid using the reflection, you may need auxiliary interface. You may also be able to use dynamic, although you will give chance to throw runtime exceptions, which will damage the performance:

  Private Zero Reference Siding Change (Object Sender, EventArg E) {Object Contact Reference = ObjectContext as Sender; If (object! = Null) {foreach (Objective entry entry in context.ObjectState Manager.Get ObjectState Entries (Entitestate.eded) {IITTIMSTAMP Entity = Entry} TeamStamp with INTTI; if (unit! = Empty) {entity.DateCreated = DateTime .Now;}}}}  

Comments