c# - LinqToSQL and auditing changed fields -


Here is one of these LinqToSQL queries where I'm sure I should remember the boat somewhere, because o behave / r Designers are very amazed at me ...

I have a base class for the Linux subclass table, which I have called LinqedTable I capture all the properties of descent sections and others To achieve the standard goods, the reflection has been successfully applied.

Now I have to do some automatic audits of my tables so that whenever the LinqedTable record is inserted or deleted, or a field value changes, To enter a record in, change the type of name, the name of the field, and its pre-and post-save value.

I thought I could do it by using the PropertyChanging event, keeping track of all the changed properties before saving one, after each submitChanges () Call but - the code generated from the O / R designer, for some strange reason, does not give you the name of the property in the PropertyChanging event - it sends an empty string! ( Why ?! ) It sends does PropertyChanged the name of the property in the event, but it is already too late to get the original value It's gone.

I have caught all the basic values ​​of all properties using the OnLoaded () partial method - but it is private by definition, and I have access to that method in the base Classroom is required Even if I used the reflection to capture that method, it would mean that I would have to apply the other half of the partial method for all my tables, which dashed away the purpose of participating is!

So what would you recommend to do this audit functionality?

You can use GetChangeSet on the Data Context so that you can update, include and update all the tables in any reference. Remove list can be found. You can use ITable.GetOriginalEntityState to retrieve the original values ​​of a converted unit. However, when you retrieve the original values ​​of a deleted or updated record, the associations will not be available, so you only have to rely on foreign key values ​​in that area if you need to take action on the respective organizations

You can use an iTable.NetModified member to help you recover only those values.


Comments