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?
dc.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, item);
Sounds like your trying to deal with concurrency issues? This is where when you submit, the database has already changed which causes your submit to fail. Let me know if this is what your after:
This pattern does the heavy lifting for you on concurrency issues. The RefreshMode has overloads to either force your change in, refresh the latest values EXCEPT your change, or let the database overwrite your changes. You can then submit again. Note that committing in full is a recursive process, your subsequent call to submit changes can also fail.
The easiest way to handle this is to treat the
DataContext
as 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.