本文整理汇总了C#中TransactionManager.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# TransactionManager.Commit方法的具体用法?C# TransactionManager.Commit怎么用?C# TransactionManager.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TransactionManager
的用法示例。
在下文中一共展示了TransactionManager.Commit方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Instead01
private void Instead01(TransactionManager tm, Customer cus)
{
MessageBox.Show("Something...");
// Begin the transaction after the message box,
// e.g. if you want to prompt them to do something before saving.
tm.BeginTransaction();
DataRepository.CustomerProvider.Insert(tm, cus);
tm.Commit();
}
示例2: Instead02
private void Instead02(TransactionManager tm, Customer cus)
{
tm.BeginTransaction();
DataRepository.CustomerProvider.Insert(tm, cus);
tm.Commit();
// Or, show the message box after the transaction completed,
// e.g. to notify them of an event after saving
MessageBox.Show("Something...");
}
示例3: ApplyRecord
/// <summary>
/// Apply a record to placeholders
/// </summary>
/// <param name="placeHolders">List of placeholder which should be applied</param>
/// <param name="recordName">Name of record</param>
/// <returns>Return true if one or more was applied</returns>
public static void ApplyRecord(IEnumerable<PlaceHolder> placeHolders, string recordName)
{
using (Transaction transaction = new TransactionManager().CreateTransaction())
{
foreach (PlaceHolder placeHolder in placeHolders)
{
placeHolder.ApplyRecord(recordName, true); // apply (with page data)
transaction.Commit(); // needed if not placed in project
}
}
}
示例4: BadlyMisplacedCode
// SAMPLE 01
//
// As mentioned in "C01_TransactionManager," the idea behind transactions
// is that it should surround a block of code that either saves everything
// or nothing.
//
// Here is the thing to remember: While the transaction is open it will prevent
// anything from accessing the database tables that you are busy with. This is
// to prevent "dirty" or incomplete records.
//
// The caveat: you want your transaction to execute as fast as possible. Be
// like a ninja: get in, do your thing, and get out.
//
private void BadlyMisplacedCode(TransactionManager tm, Customer cus)
{
tm.BeginTransaction();
DataRepository.CustomerProvider.Insert(tm, cus);
MessageBox.Show("Something...");
tm.Commit();
// Can you see it?
// This code will block the Customer table on the entire branch until the user
// clicks "OK" on the message box. The impact of this is enourmous.
}
示例5: CreateRecordWithValueAndApply
/// <summary>
/// Create a record to a placeHolder by name and apply a record
/// </summary>
/// <param name="placeHolders">List of placeholder which should be applied</param>
/// <param name="placeHolderName">Name of placeholder</param>
/// <param name="recordName">Name of record</param>
/// <param name="variableName">Variable to set</param>
/// <param name="value">New value of the variable</param>
/// <returns>Return true if one or more was applied</returns>
public bool CreateRecordWithValueAndApply(PlaceHolder[] placeHolders, string placeHolderName, string recordName, string variableName, string value)
{
List<PlaceHolder> foundPlaceHolder = placeHolders
.Where(placeHolder => placeHolder.Name.Equals(placeHolderName)) // name
.ToList();
foreach (PlaceHolder placeHolder in foundPlaceHolder)
{
placeHolder.AddRecord(recordName);
placeHolder.set_Value(recordName, variableName, value);
using (Transaction transaction = new TransactionManager().CreateTransaction())
{
placeHolder.ApplyRecord(recordName, true); // apply (with page data)
transaction.Commit(); // needed if not placed in project
}
}
return foundPlaceHolder.Any(); // true == found | false == not found
}