Skip to content

itenium-be/DbAuditWithEF

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Database Auditing with EntityFramework

itenium blog post

Spin up a SqlServer

docker compose up -d --build

Port: 5174 Login: sa / password123!

Build & Test

dotnet build DbAuditWithEF.slnx
dotnet test DbAuditWithEF.slnx

EF Migrations

cd DbAuditWithEF.DatabaseTrigger

# Install
dotnet tool install --global dotnet-ef

# Create
dotnet ef migrations add InitialCreate
dotnet ef database update

# Delete
dotnet ef migrations remove
dotnet ef database drop -f

The Ways

  • DatabaseTrigger: Set CreatedBy/On and ModifiedBy/On with a database trigger.
  • ByEF: Same but set with Entity Framework. Use a ComplexType IAudit and overwrite manual changes to the properties.
  • ByInterceptor: Same as ByEF but using a SaveChangesInterceptor for better separation of concerns.
  • ByReflection: Totally avoid setting the properties manually by making them private and using reflection.
  • DatabaseTable: Keep changes in a separate table with a database trigger.
  • EFTable: Same but insert records with Entity Framework.

About

SQL Server & EntityFramework Core: how to audit

Resources

License

Stars

Watchers

Forks

Contributors

Languages