You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$10
For Premium members:
In this article you will learn how to override SaveChanges in Entity Framework.
IntroductionIn Entity Framework starting from version 4 and above we have the option to override the default “SaveChanges()” method and use some custom code or some business logic before committing the changes to the database. And this feature is very handy when we have entities with common properties that need to be handled automatically. We have encountered a few scenarios where we have entities with a modified date and modified by the user property that needs to be be updated correctly each time we deal with those entities. So rather than assigning a value to those properties every time throughout the application, what we can do is to have a single place with some logic written for the entities to populate the modified date and modified user name and than we can save the changes to the database. The scenario that I am talking about can be easily handled by overriding the “SaveChanges()” method of Entity Framework. Let's understand it with an example below.ExplanationLet us say we have three entities named Employee, Department and Employment and they look something like:
Hands on with ASP.Net MVC - Covering MVC 6