Here's another one of these LinqToSQL questions where I'm sure I must have missed the boat somewhere, because the behavior of the O/R Designer is very puzzling to me...
I have a base class for my LinqToSQL tables, which I called LinqedTable
. I've successfully used reflection to get hold of all the properties of the descendant classes and do other standard stuff.
Now I want to have some automatic auditing of my tables, so that whenever a LinqedTable
record is inserted or deleted, or a field value changes, I will insert a record into an audit table, detailing the change type, the field name, and its value pre- and post-save.
I thought I would be able to do it using the PropertyChanging
event, keeping track of all the changed properties before a save, then clearing the collection of changes after each SubmitChanges()
call. But - the generated code from the O/R designer, for some bizarre reason, doesn't give you the property name in the PropertyChanging
event - it sends an empty string! (WHY?!) It does send the property name in the PropertyChanged
event, but that's already too late for me to get the original value.
I thought to grab all the original values of all properties using the OnLoaded()
partial method - but that is private by definition, and I need access to that method in the base class. Even if I used reflection to get hold of that method, that would mean I would have to implement the other half of the partial method for every one of my tables, which kinda defeats the purpose of having inheritance!
I also can't find any suitable method in the DataContext to use or override.
So what would you recommend to get this audit functionality working?