I have some tables:
- Account (Id, Code, Name, Email, Address, Phone, CreatedDate, CreatedBy, ModifiedDate, ModifiedBy)
- Product (Id, Code, Name, Price, CreatedDate, CreatedBy, ModifiedDate, ModifiedBy)
- OrderDetail (OrderId, ProductId, Amount, Price, CreatedDate, CreatedBy, ModifiedDate, ModifiedBy)
- Param (Code, Name, Value)
And I have class/interface: - AuditableEntity (CreadtedDate, CreatedBy, ModifiedDate, ModifiedBy) - BaseEntity/CodeEntity/CommonEntity (Code)
Account, Product, OrderDetail need AuditableEntity Param needs BaseEntity
If Param needs AuditableEntity in the future, easy to attach Audit to Param.
When user add and commit entity to database, fields CreatedDate and CreatedBy are automatically added. The same thing with UpdatedDate and UpdatedBy in update/edit case.
I have implemented add or update case by create AuditableEntity and modified tt file in EF to force all entities inherit to it (but not the good practice cause some tables don't need auditing).
I think that be can use interface instead of class and let entity is partial type. But I'm not sure about that so I need your advise or if you have better design, I'm very appreciated with your help.