本文整理汇总了C#中IConnectionProvider.CommitTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# IConnectionProvider.CommitTransaction方法的具体用法?C# IConnectionProvider.CommitTransaction怎么用?C# IConnectionProvider.CommitTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IConnectionProvider
的用法示例。
在下文中一共展示了IConnectionProvider.CommitTransaction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateAll
private static int UpdateAll(IConnectionProvider conn, IEntity rootEntity, DbRelation recursiveRelation, UpdateList setExpressions, int beginAtLevel, int endAtLevel)
{
// Stop condition: rowsAffected == 0
int totalRowsAffected = 0;
bool isLocalConn = !conn.IsOpen;
try
{
if (isLocalConn)
conn.BeginTransaction();
// We need to perform COUNT at least once to determine whether rowsAffacted returned by UPDATE can be trusted.
RowsAffectedCredibility trustRowsAffected = RowsAffectedCredibility.NotDetermined;
bool reachedEndLevel = false;
int level = beginAtLevel;
do
{
// Dependening on DBMS configuration, update statements may automatically return the number of rows affected.
int rowsAffectedReturnedByEngine = UpdateAtLevel(conn, rootEntity, recursiveRelation, setExpressions, level);
// We need to perform manual counting for as long as rows affected cannot be trusted.
int? manualNodeCount = CountNodesAtLevelIfRowsAffectedCannotBeTrusted(conn, rootEntity, trustRowsAffected, recursiveRelation, level);
// Evaluation which determines whether rows affected may be trusted takes place only once, ie. if not yet determined.
bool evaluateRowsAffectedCredibility = (trustRowsAffected == RowsAffectedCredibility.NotDetermined) && (manualNodeCount.HasValue);
if (evaluateRowsAffectedCredibility)
{
bool engineCountMatchesManualCount = (rowsAffectedReturnedByEngine == manualNodeCount.Value);
trustRowsAffected = (engineCountMatchesManualCount) ? RowsAffectedCredibility.Trusted : RowsAffectedCredibility.Untrusted;
}
// Manual node count is null if we have determined that rows affected value returned by engine is credible.
int rowsUpdatedInCurrentLevel = manualNodeCount ?? rowsAffectedReturnedByEngine;
totalRowsAffected += rowsUpdatedInCurrentLevel;
// Inspect stop condition before level variable is increased.
reachedEndLevel = IsEndLevelReached(endAtLevel, level, rowsUpdatedInCurrentLevel);
// Next level.
level++;
} while (!reachedEndLevel);
if (isLocalConn)
conn.CommitTransaction();
}
finally
{
if (isLocalConn)
conn.CloseConnection();
}
return totalRowsAffected;
}
示例2: UpdateWithLeafFilter
private static int UpdateWithLeafFilter(IConnectionProvider conn, IEntity rootEntity, DbRelation recursiveRelation, UpdateList setExpressions, SearchCondition leafFilter, int beginAtLevel, int endAtLevel)
{
// Stop condition: final level reached (tree depth is measured).
// It's possible that at some intermediate levels no records satisfy the specified criteria.
// Nevertheless, the algorithm must proceed to the next level where it might find matching records.
// This behavior simulates the behavior of recursive CTEs.
int totalRowsAffected = 0;
bool isLocalConn = !conn.IsOpen;
try
{
if (isLocalConn)
conn.BeginTransaction();
endAtLevel = GetEndLevel(conn, rootEntity, recursiveRelation, endAtLevel);
bool reachedEndLevel = false;
int level = beginAtLevel;
do
{
UpdateStatement updateAtLevel = CreateUpdateLevelStatement(rootEntity, recursiveRelation, setExpressions, leafFilter, level);
totalRowsAffected += updateAtLevel.Execute(conn);
reachedEndLevel = (level >= endAtLevel);
level++;
} while (!reachedEndLevel);
if (isLocalConn)
conn.CommitTransaction();
}
finally
{
if (isLocalConn)
conn.CloseConnection();
}
return totalRowsAffected;
}