Garcia Julien
Garcia Julien

Reputation: 756

cancel update in datacontext = LInq

I would like to know if its possible to discard changes of only one record of only one table in datacontext.

I use databind to bind my controls on a form. I modify one record at a time. after the modification, the user have to hit save button to validate. But he can hit cancel. I would like that the cancel button discard all the changes that the user has done. Is it possible?

Ju

Upvotes: 0

Views: 895

Answers (3)

Peter Willis
Peter Willis

Reputation: 956

If you don't call .SubmitChanges on the DataContext then the changes will not be applied to the database.

It's all about the DataContext when considering the change tracking of your entities.

If you would like to clear all changes, then close the datacontext and open a new one.

Upvotes: 2

Garcia Julien
Garcia Julien

Reputation: 756

Thanks for your response, I found a solution, i reload the datacontext when i hit cancel. It's working and it's faster. Thanks

Upvotes: 0

Ben
Ben

Reputation: 3912

Make it so your Dialog is a dumb UI. I.e, it handles all of the input of the data, but doesn't persist any data. So if you are using a dialog called from a form - have something like

If (myDlg.ShowDialog() = DialogResult.Ok)
     MyDataContext.SubmitChanges()
End If

This way, if your dialog doesn't return Ok (i.e. if they click cancel, the DataContext wont persist the results bak to the database.

This makes for reusable code as well.

Upvotes: 2

Related Questions