in my data layer class I have created a function to manually refresh the data source.
Public Sub DiscardAllChanges() _Context.Refresh(RefreshMode.OverwriteCurrentValues) End Sub
The problem is that the context ChangeSet after this operation still trace the previous operation of Insertion, Deletion and Update that I made calling manually InsertOnSubmit, etc.
Is it possible to clear also the ChangeSet in some way? Or if not can you suggest me another solution? Do I have to create a ChangeSet layer in the Business?
The easiest way to handle this is to treat the
DataContextas your unit of work. Perform an atomic set of related operations on a singleDataContext, then after either success or failure,Dispose()it (ideally viausing) and throw it away.Start you next set of operations on a new
DataContext. Likewise, you can re-query for data.On an object-by-object basis, you can use
GetOriginalEntityState(on the table) to get the original values, but you’d need to re-apply to a ‘live’ object, and this doesn’t handle the delete/insert cases.