ORM: 开发自己的Data Access Application Block - Part III
2008-12-06 10:15:40 来源:WEB开发网Part IV: Transaction
定义了3个基于Transaction的方法BeginTransaction,Commit和RollBack,使Developer显示地开始和结束一个Transaction,这样他可以很直观地把所需的操作纳入某个Transaction中。
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using Artech.ApplicationBlock.DataMapping;
using Artech.ApplicationBlock.Common;
using Artech.ApplicationBlock.Common.Exceptions;
namespace Artech.ApplicationBlock.DataAccess
{
/**//// <summary>
/// Database defines a series of database-based operations.
/// </summary>
public abstract partial class Database : IDisposable
{
DbTransaction _transaction;
Transaction based operation#region Transaction based operation
public void BeginTransaction()
{
if (this.Connection.State != ConnectionState.Open)
{
this.Connection.Open();
}
this._transaction = this.Connection.BeginTransaction();
}
public void Commit()
{
if (this._transaction == null)
{
throw new DataAccessException(CommonConstant.DataAccess.Messages.NotBegunTransaction);
}
this._transaction.Commit();
}
public void RollBack()
{
if (this._transaction == null)
{
throw new DataAccessException(CommonConstant.DataAccess.Messages.NotBegunTransaction);
}
this._transaction.Rollback();
}
public DbTransaction Transaction
{
get
{
return this._transaction;
}
set
{
this._transaction = value;
}
}
#endregion
}
- ››自己写的一个php基于phpQuery的通用采集类
- ››开发Android 日历教程
- ››开发学院总结 Win 8实用技巧大全
- ››开发学院原创教程:把win8的IE10放桌面上方法(非...
- ››开发者眼中的Windows Phone和Android
- ››开发学院教你用SQL 语句最快速清空MySQL 数据表的...
- ››自己动手写iPhone wap浏览器之界面架构篇
- ››自己也能DIY个性真人QQ表情
- ››自己动手!巧法让酷狗动感歌词更完美
- ››自己编译Google Android内核的Linux源码
- ››自己写的一个jquery模板引擎(json比较好用)
- ››开发一个自己的HTML在线编辑器(一)
赞助商链接