Linq to SQL: getting old values of changed rows

2019-09-14 05:01发布

问题:

I have an editable grid bound to a Linq to SQL table. I use SubmitChanges to save changes and I need a way to get old values of the changed rows. I tried getting context.GetChangeSet().Updates but the problem is the rows in this collection has new values not the old ones, even before calling SubmitChanges(). How can I do this?

回答1:

The L2S cache will contain the old values. Even after you call SubmitChanges(). I found this out the hard way. The cache will contain the old values until you call context.Refresh() to refresh all the rows. So, you can simply re-retrieve the values. L2S will get them from cache, which will be the old values.

Randy