trans中文是什么意思

发布网友 发布时间:2022-04-23 10:01

我来回答

2个回答

懂视网 时间:2022-04-12 13:31

Enterprise Libray 3.0已经发布了,具体可参见TerryLee的 Enterprise Library 3.0 发布.下载了看看,有非常激动人心的更新.我只是看看Data Access Application Block代码,代码中有这个类TransactionScopeConnections,是个内部类,设计意图很明显就是使用数据库

Enterprise Libray 3.0已经发布了,具体可参见TerryLee的 Enterprise Library 3.0 发布.下载了看看,有非常激动人心的更新.我只是看看Data Access Application Block代码,代码中有这个类TransactionScopeConnections,是个内部类,设计意图很明显就是使用数据库的事务模型.我觉得设计为内部类有点瑕疵,我的习惯是事务和提交在业务逻辑层. .NET 2.0的System.Transactions应该是一个更好的选择。就将Data Access Application Block的QuickStart例子代码:

///


/// Transfers an amount between two accounts.
///

/// Amount to transfer.
/// Account to be credited.
/// Account to be debited.
/// true if sucessful; otherwise false.
/// Demonstrates executing multiple updates within the
/// context of a transaction.

public bool Transfer(int transactionAmount, int sourceAccount, int destinationAccount)
{
bool result = false;

// Create the Database object, using the default database service. The
// default database service is determined through configuration.
Database db = DatabaseFactory.CreateDatabase();

// Two operations, one to credit an account, and one to debit another
// account.
string sqlCommand = "CreditAccount"
DbCommand creditCommand = db.GetStoredProcCommand(sqlCommand);

db.AddInParameter(creditCommand, "AccountID", DbType.Int32, sourceAccount);
db.AddInParameter(creditCommand, "Amount", DbType.Int32, transactionAmount);

sqlCommand = "DebitAccount"
DbCommand debitCommand = db.GetStoredProcCommand(sqlCommand);

db.AddInParameter(debitCommand, "AccountID", DbType.Int32, destinationAccount);
db.AddInParameter(debitCommand, "Amount", DbType.Int32, transactionAmount);

using (DbConnection connection = db.CreateConnection())
{
connection.Open();
DbTransaction transaction = connection.BeginTransaction();

try
{
// Credit the first account
db.ExecuteNonQuery(creditCommand, transaction);
// Debit the second account
db.ExecuteNonQuery(debitCommand, transaction);

// Commit the transaction
transaction.Commit();

result = true;
}
catch
{
// Rollback transaction
transaction.Rollback();
}
connection.Close();

return result;
}
}

按照TransactionScope类进行改造,试验成功了,代码如下:

public bool Transfer(int transactionAmount, int sourceAccount, int destinationAccount)
{
bool result = false;
Database database = DatabaseFactory.CreateDatabase();

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
TestCommand1(database, transactionAmount, sourceAccount);
TestCommand2(database, transactionAmount, destinationAccount);
scope.Complete();
result = true;
}
return result;

}

private void TestCommand1(Database db, int transactionAmount, int sourceAccount)
{
string sqlCommand = "CreditAccount"
DbCommand creditCommand = db.GetStoredProcCommand(sqlCommand);

db.AddInParameter(creditCommand, "AccountID", DbType.Int32, sourceAccount);
db.AddInParameter(creditCommand, "Amount", DbType.Int32, transactionAmount);

// Credit the first account
db.ExecuteNonQuery(creditCommand);
}

private void TestCommand2(Database db, int transactionAmount, int destinationAccount)
{
string sqlCommand = "DebitAccount"
DbCommand debitCommand = db.GetStoredProcCommand(sqlCommand);

db.AddInParameter(debitCommand, "AccountID", DbType.Int32, destinationAccount);
db.AddInParameter(debitCommand, "Amount", DbType.Int32, transactionAmount);

// Debit the second account
db.ExecuteNonQuery(debitCommand);
}

DAAB 在一个事务中可以在一个数据库连接中检测到几个命令的执行,这样可以避免虽然一个数据库连接执行的几个命令而启用 分布式事务 。在企业类库2.0的DAAB常常启用了分布式事务,就凭这一点,使用企业类库2.0的同学们有必要升级到企业类库3.0。

Parameter Discovery on Ms Access and SqlServer. using Microsoft Patterns and Practices DataBlock version 3.0 final
http://www.codeproject.com/useritems/Parameter_DiscoveryV292.asp

热心网友 时间:2022-04-12 10:39

trans

英 [trɑ:nz]  美 [trænz] 

abbr. 翻译(translate)

pref. 表“横穿”;表“进入”

n. 传动装置;变速箱

[例句]

What's needed is a recognition that salt, like fat and trans fats, is not good for you. 

需要认识到的是,盐和脂肪以及转化脂肪一样,对于每个人来讲是不好的。

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com