There are certain cases for values that should always be updated when an object is persisted to the database. I can find no entry point for doing this other than overriding DbContext.ValidateEntity
and modifying the CurrentValues
property collection, but in my opinion using a validation method to modify object properties carries a very bad smell. Is there any other means of doing this?
Asked
Active
Viewed 174 times
0

ProfK
- 49,207
- 121
- 399
- 775
-
1You are right about validation - overriding validation to change property values may be dangerous (one of the reason is that detect changes is not called after validation has completed). What you can do however is to override SaveChanges and modify entities and then call base.SaveChanges to follow the regular workflow. – Pawel Apr 08 '12 at 05:33
-
2Check this answer http://stackoverflow.com/questions/7641552/overriding-savechanges-and-setting-modifieddate-but-how-do-i-set-modifiedby/7642041#7642041 – Eranga Apr 08 '12 at 06:03
1 Answers
0
Thanks to Eranga's comment above, I found this answer is a perfect fit for my question.
It describes how to override SaveChanges
on my dbcontext and set the properties I would like to there.