Editing a Log Using LINQ to SQL

In the system that I create, the client requires that all changes in the data are registered in the database table - when registering only changes (i.e. if they change only one value in a form full of 10 fields, this will be an audit that one change ) So essentially, I need to be able to compare old values ​​with new values.

This, of course, is easy - I did it before, but it was pretty dirty - I manually checked each field in the database and compared it with a new one to decide whether to check it. Is there an easier way, perhaps to automatically get the changed column name / values? Or do I need to do this in a "dirty" way?

Almost all the changes that need to be registered are made using LINQ to SQL - is there possibly a way to compare the database table with the changed one before sending the send changes?

+3
source share
4 answers

I used an article on Code Project called Automatic Event Logging in LINQ . This worked very well for us, it also does what you requested, as it only logs changes. If an entry is inserted, each update is displayed as a separate row in the database that tracks PK, field name, old value and new value. Of course, he also keeps track of who performed the action and when. It tracks all actions: create, read, update and delete.

, , .

+2

? .

0

See CDC (collection of change data) on the Sql server may help. IIRC, it was introduced in MSSQL2008. But it is at the database level! So it may not qualify as an answer! Hope this helps.

0
source

I have used http://doddleaudit.codeplex.com/ with great success.

It’s easy to set up and add an “automatic” log to the context of your data.

0
source

Source: https://habr.com/ru/post/1794159/


All Articles