1

I need to be able to save all the data that gets updated like so.

User inserts a car Model (Make, Type, Year). Comes back and Updates the Year. I need to be able to save both so they have a history of all the work that they did. What is the best way to do that?

Mike Diaz
  • 2,231
  • 4
  • 31
  • 55

2 Answers2

2

There are a number of ways to do this. One way is to write some SQL triggers and do it entirely in the database. Have a look here for some clues:

Another way is to do the auditing within the Entity Framework code. There is a nuget package called AuditDbContext with the source on Codeplex.

You need to decide if you want to do the auditing in EF or in SQL. Obviously if you need to audit everything and you might sometimes access the database from different applications which don't use the same EF datalayer (e.g. different technologies, etc), then SQL triggers might well be the way to go.

Community
  • 1
  • 1
Tom Chantler
  • 14,117
  • 4
  • 46
  • 51
0

Maybe (if you are facing the "history" issue more often) the CQRS pattern is of interest for you; a good primer, Microsoft on CQRS. There is a framework build on .NET for this pattern (I have not tried it yet): NCQRS.

If you really just want the requirement in your question fulfilled now and you are using SQL Server 2010 or later, then Change Tracking may be another option. I would prefer that to triggers (but in the end all such dark processing logging solutions introduce additional risk).

TvdH
  • 896
  • 10
  • 27