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.
///
///
/// 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

enterprise是Windows系统企业版,Windows企业版主要面向大中型企业,其加入了Direct Access、Windows To Go Creator、AppLokcer、BranchCache等多种实用功能。

li是HTML标记语言中的一个元素,用于创建列表。li代表列表项,它是ul或ol的子元素,li标签的作用是定义列表中的每个项目。在HTML中,li元素通常与ul或ol元素配合使用来创建有序或无序列表,无序列表使用ul元素,列表项用li元素表示,而有序列表则使用ol元素,同样也用li元素表示。

在html中,li的英文全称为“list item”,意思为“列表项”,是一个定义列表项目的元素标签,语法“<li>列表项内容</li>”;“<li>”标签可用在有序列表 “<ol>”和无序列表“<ul>”中。

使用transactionscope的步骤:1、引入命名空间;2、创建TransactionScope对象;3、开始事务;4、执行数据库操作;5、提交或回滚事务。详细介绍:1、引入命名空间,在使用TransactionScope之前,需要先引入System.Transactions命名空间;2、创建TransactionScope对象,在需要使用事务的代码块中等等。

transactionscope的使用方法:1、引入命名空间;2、创建TransactionScope对象;3、开始事务;4、执行数据库操作;5、提交或回滚事务。详细介绍:1、引入命名空间,在使用TransactionScope之前,需要引入System.Transactions命名空间;2、创建TransactionScope对象,使用TransactionScope时等等。

css去掉li默认样式的方法:1、创建一个HTML示例文件;2、添加li标签内容;3、在css中通过将“list-style-type”属性设置为“none”即可去掉li默认样式。

本站11月16日消息,在今天的MicrosoftIgnite2023开发者大会上,微软宣布BingChat及其企业高级版BingChatforEnterprise正式更名为Copilot!微软通讯总监CaitlinRoulston表示,公司决定将"BingChatEnterprise"更名为"Copilot",这一改动体现了微软为消费者和商业客户打造统一的Copilot体验的愿景当然,不仅仅是名字变了。从12月1日起,使用企业账户(确切地说是Microso

css li显示不同颜色的实现方法:1、通过“ul li::marker {color: #3860f4;}”属性实现修改li颜色;2、通过“li:before {content: "";width: 6px;height: 6px;display: inline-block;border-radius: 50%;background: #4F8EFF...”属性设置颜色。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SAP NetWeaver Server Adapter for Eclipse
Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

mPDF
mPDF は、UTF-8 でエンコードされた HTML から PDF ファイルを生成できる PHP ライブラリです。オリジナルの作者である Ian Back は、Web サイトから「オンザフライ」で PDF ファイルを出力し、さまざまな言語を処理するために mPDF を作成しました。 HTML2FPDF などのオリジナルのスクリプトよりも遅く、Unicode フォントを使用すると生成されるファイルが大きくなりますが、CSS スタイルなどをサポートし、多くの機能強化が施されています。 RTL (アラビア語とヘブライ語) や CJK (中国語、日本語、韓国語) を含むほぼすべての言語をサポートします。ネストされたブロックレベル要素 (P、DIV など) をサポートします。

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

Dreamweaver Mac版
ビジュアル Web 開発ツール

ホットトピック



