Friday, 15 April 2011

winforms - EntityFramework 6 Transaction.Rollback and Commit -


I need to create a cancel button that will return all the changes since the last reference is saved. I got this rollback used to work on a button click. However, the datagrid view does not reflect change. If I leave the program then I can see that no data was changed.

I have got the following form to work on (I do not see any error in the output window) However, the statement that I have read in reference to the statement is still in this situation Applicable? I used rollback and tried / saved the method of saving, but this plane object 'does not look right. What if I was born in any other form, whether it will add to the current transaction or not?

  /// & lt; Summary & gt; /// & lt; / Summary & gt; Public Partial Category Form 2: Form (/// & lt; Summary & gt; /// & lt; / summary & gt; Private Test Content Text _ Convert; /// & lt; Summary & gt; /// & Lt; / summary & gt; Private DbContextTransaction _transaction; /// & lt; Summary & gt; /// & lt; / summary & gt; Public Form 2 () {Initialization ();} /// & lt; Summary & gt; /// & lt; / summary & gt; /// & lt; param name = "e" & gt; & lt; / param & gt; Safe Override Zero OnClosing (CancelEventArgs e) {base.OnClosing (E); _transaction.Rollback (); _context.Dispose ();} /// & lt; summary & gt; /// & lt; / summary & gt; /// & lt; param name = "e" & Gt; & lt; / param & gt; Secure Override Zero Onload (EventAgsg E) {base.OnLoad (e); _context = New TestContext (); _transaction = _context.Database.BeginTransaction (); SetupDataGridView ();} /// & lt; Summary & gt; // & Lt; param name = "sender" & gt; & lt; / param & gt; /// & lt; param name = "e" & gt; & lt; / lt; / Param> Private Zero btnCancel_Click (Object Sender, EventArgs e) {_transaction.Rollback (); _context = New TestContext (); SetupDataGridView (); _transaction = _context.Database.BeginTransaction (); } /// & lt; Summary & gt; /// & lt; / Summary & gt; /// & lt; Param name = "sender" & gt; & Lt; / Param & gt; /// & lt; Param name = "e" & gt; & Lt; / Param & gt; Private Zero btnSave_Click (Object Sender, EventArgs E) {Valid (); PersonDataGridView.CommitEdit (DataGridViewDataErrorContexts.Commit); _context.SaveChanges (); _transaction.Commit (); PersonBindingSource.ResetBindings (true); _transaction = _context.Database.BeginTransaction (); } /// & lt; Summary & gt; /// & lt; / Summary & gt; Private Zero SetupDataGridView () {_context.People.Load (); ObservableCollection & LT; Person & gt; People = _context.People.Local; PersonBindingSource.DataSource = people.ToBindingList (); PersonBindingSource.RaiseListChangedEvents = True; PersonDataGridView.AutoGenerateColumns = false; PersonDataGridView.DataSource = PersonalBindingSource; }}  


No comments:

Post a Comment