本文整理汇总了C#中BrightPlatformEntities.AcceptAllChanges方法的典型用法代码示例。如果您正苦于以下问题:C# BrightPlatformEntities.AcceptAllChanges方法的具体用法?C# BrightPlatformEntities.AcceptAllChanges怎么用?C# BrightPlatformEntities.AcceptAllChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BrightPlatformEntities
的用法示例。
在下文中一共展示了BrightPlatformEntities.AcceptAllChanges方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: m_bwUpdateMasterDataContact_DoWork
//.........这里部分代码省略.........
if (_drNewContact != null)
_dtNewContacts.Rows.Add(_drNewContact);
}
#endregion
/**
* start the insert/update transaction.
* updates will be first processed over new data.
*/
#region Code Logic
SqlConnection _sqlConnection = new SqlConnection(UserSession.ProviderConnection);
_sqlConnection.Open();
SqlTransaction _sqlTransaction = _sqlConnection.BeginTransaction();
using (TransactionScope _efDbTransaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() {
Timeout = TimeSpan.FromMinutes(120),
IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted
})) {
try {
/**
* start updating records.
* transaction will not be saved until _efDbModel.AcceptAllChanges() is called.
*/
if (_lstUpdatedContacts.Count > 0) {
contact _item = null;
int _id = 0;
for (int x = 0; x < _lstUpdatedContacts.Count; x++) {
_id = _lstUpdatedContacts[x].id;
_item = _efDbModel.contacts.FirstOrDefault(i => i.id == _id);
_efDbModel.contacts.ApplyCurrentValues(_lstUpdatedContacts[x]);
}
_efDbModel.SaveChanges();
}
//ObjectContact.SaveContacts(_lstUpdatedContacts, _efDbModel);
/**
* process new records using bulk insert.
* commit and accept all changes to the database.
* to be updated records will be committed on _efDbModel.AcceptAllChanges() call.
*/
if (_dtNewContacts.Rows.Count > 0)
DatabaseUtility.ExecuteBulkProcessing("vw_contacts", _dtNewContacts, _sqlConnection, _sqlTransaction);
/**
* commit only if has records to insert/update.
*/
if (_dtNewContacts.Rows.Count > 0)
_sqlTransaction.Commit();
if (_lstUpdatedContacts.Count > 0) {
_efDbModel.AcceptAllChanges();
_efDbTransaction.Complete();
}
tbxImportFileContact.Text = "";
cboSheetNameContact.Properties.Items.Clear();
cboSheetNameContact.Text = "";
gcMatchedColumnContact.DataSource = null;
gcImportFileDataContact.DataSource = null;
lblRecordStatisticContact.Text = " Number of Records: 0";
WaitDialog.Close();
MessageBox.Show("Successfully saved items to contacts master data.", "Bright Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
WaitDialog.Show("Initializing ...");
}
catch (Exception Ex) {
WaitDialog.Close();
MessageBox.Show(string.Format("Transaction rolled backed due to the ff:{0}{0}{1}", Environment.NewLine, Ex.Message), "Bright Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
WaitDialog.Show("Initializing ...");
_efDbTransaction.Dispose();
_sqlTransaction.Rollback();
_efDbModel = null;
_sqlConnection = null;
this.SetEditableControlsContact(true);
e.Cancel = true;
return;
}
finally {
_efDbTransaction.Dispose();
_efDbModel = null;
_sqlConnection = null;
}
WaitDialog.Close();
}
#endregion
/**
* delete the temporary excel file created during the matching
*/
if (File.Exists(m_sFileNameContact))
File.Delete(m_sFileNameContact);
this.SetEditableControlsContact(true);
btnUpdateToGridContact.Enabled = false;
btnUpdateToMasterDataTableContact.Enabled = false;
WaitDialog.Close();
}));
e.Cancel = true;
}