private void setDisableAV(System.Data.Objects.ObjectContext dc, bool value, bool save) { using (var t = new TransactionScope()) { bool changed = false; if (this.AtrybutTowaru != null) { if (this.AtrybutTowaru.DisableAVList != value) { this.AtrybutTowaru.DisableAVList = value; changed = true; } if (!value && this.Towar.DisableAVList) { this.Towar.DisableAVList = false; changed = true; } } else if (this.Towar.DisableAVList != value) { this.Towar.DisableAVList = value; changed = true; } if (changed && save) { dc.SaveChanges(); dc.Refresh(System.Data.Objects.RefreshMode.StoreWins, this); } t.Complete(); } }
public bool SaveChanges(System.Data.Objects.ObjectContext dataContext) { using (var t = new System.Transactions.TransactionScope()) { dataContext.SaveChanges(); dataContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, this); t.Complete(); } return(true); }
/// <summary> /// Saves all context changes /// </summary> public void SaveChanges() { _context.SaveChanges(); }
private static void SaveMyChanges(System.Data.Objects.ObjectContext context) { if (_persistedEntriesList == null) { _persistedEntriesList = new List <PersistedStateEntry>(); } try { context.SaveChanges(); } catch (OptimisticConcurrencyException ex) { var stateentries = ex.StateEntries; ObjectStateEntry conflictEntry = ex.StateEntries[0]; string errorMessage = null; if (ex.InnerException != null) { errorMessage = ex.Message + System.Environment.NewLine + ex.InnerException.Message; } else { errorMessage = ex.Message; } if (!conflictEntry.IsRelationship) { //persist the entityentry var pEntry = new PersistedStateEntry(conflictEntry.EntityKey, conflictEntry.CurrentValues.DataRecordInfo, (IExtendedDataRecord)conflictEntry.OriginalValues, conflictEntry.Entity, ex.Message); //don't forget relatoinships, need to do this before detaching entity if (ex.StateEntries.Count > 1) { for (var i = 1; i < ex.StateEntries.Count; i++) { //ignore Unchanged relatoinship entries if (ex.StateEntries[i].State != EntityState.Unchanged) { pEntry.AddRelationships(ex.StateEntries[i]); } } } context.Detach(conflictEntry.Entity); _persistedEntriesList.Add(pEntry); //If TypeOf conflictEntry.Entity Is Contact Then // ContactRefresh(conflictEntry, context) //ElseIf TypeOf conflictEntry.Entity Is Payment Then // PaymentRefresh(conflictEntry, context) //Else // context.Refresh(RefreshMode.ClientWins, conflictEntry) //End If //Dim detailstring = conflictEntry.EntryDetails(context) // context.Refresh(RefreshMode.ClientWins, conflictEntry.Entity) } //handle concurrency exception here //then try again SaveMyChanges(context); } catch (System.Data.EntityCommandCompilationException ex) { } catch (System.Data.EntityCommandExecutionException ex) { } catch (System.Data.EntitySqlException ex) { } catch (Exception ex) { //handle other exceptions } }
virtual public void Commit() { DataContext.SaveChanges(); }