I am evaluating Entity Framework 4.0 and I am wondering how I can get access to entities just before they are saved to set DateCreated.
With NHibernate this could be done using a listener, if that helps?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could use the
ObjectContexteventSavingChanges, retrieve the entities that have an the stateEntityState.Added, and set the DateCreated for those objects. You might need a helper interface to facilitate a more agnostic handler and avoid the use of reflection. You might also be able to use dynamic, although you would run the chance of runtime exceptions being thrown, which would hurt performance: