What is created date and Modified date and when we use this?
Keeping CreatedDate, ModifiedDate, CreatedBy, and ModifiedBy or auditing columns in the database tables is part of good practices for database design. these columns help in many scenarios like select all the record by created date,Modified date.
If you have any transaction table like customer info, Order Details,EmployeeInfor then you can use CreatedDate and ModifiedDate.
If you have any tables which have user action like Order is placed by this user and modified by this user in this scenario you can use all four columns CreatedDate, ModifiedDate, CreatedBy, and ModifiedBy
Let’s start with some coding part.
While adding or modifying the employee class you have to take care of these two properties because we can not provide these properties in the user form as input.
Note: If you have one or two classes then you can manage to add additional code without any issue but if you have thousands of classes then obviously you will think of some generic code which can handle these two properties automatically while doing all add or edit operation.
As we discussed earlier auditing information is not required in all the tables.
There are two advantages of using BaseClass here
- No need to write auditing columns properties in all the entity classes
- It will be easy to differentiate between the Auditing entity vs normal entity class
If you are using entity framework then we can override the SaveChanges method inside the DbContext class and perform our auditing columns logic.
- Deependra is a Senior Developer with Microsoft technologies, currently working with Opteamix India business private solution. In My Free time, I write blogs and make technical youtube videos. Having the good understanding of Service-oriented architect, Designing microservices using domain driven design.