Skip to content

Keeping a Change History With LinqToSQL

June 9, 2014
tags: ,

So in a lot of applications you want to keep track of what your users are doing to your precious data.  What was it and what did they change it to?  I remember setting up entities with a bunch of isDirty flags or adding to a list in set methods which are all fine but if you’re using LinqToSQL, you’re already covered.

Just before you do a submit changes all you have to do is call GetModifiedMembers on your table object.  Like so:

var foo = currentView.db.Accounts.GetModifiedMembers(currentView.EditAccount);

Then you can loop through any and all results to get .Member.Name, or .OriginalValue or .CurrentValue

PS.  I realize that you can just do this invisibly by overriding OnChanging classes but if you need to be selective the above is a solid method.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: