日期:2014-05-17 浏览次数:20835 次
/// <summary>
/// 业务逻辑基本操作类,实现对实体‘T’的基本操作(增、删、查、改、检查)
/// </summary>
public static class DBHelper
{
/// <summary>
/// 新增(含事务)
/// </summary>
/// <typeparam name="T">Entities对象</typeparam>
/// <param name="entity">将保存的实体</param>
/// <returns>执行成功影响的行数,否则抛出异常</returns>
public static int Insert<T>(T entity, DbTransaction trans) where T : Entity, new()
{
return ORMHelper.GetGateway(trans).Save<T>(entity, trans);
}
/// <summary>
/// 根据实体修改(含事务)
/// </summary>
/// <typeparam name="T">Entities对象</typeparam>
/// <param name="entity">将修改的实体</param>
/// <returns>执行成功影响的行数,否则抛出异常</returns>
public static int Update<T>(T entity, DbTransaction trans) where T : Entity, new()
{
ReflectionBase.SetValue(entity, "SyncTime", DateTime.Now);
return ORMHelper.GetGateway(trans).Save<T>(entity, trans);
}
}
//------------------------------------
/// <summary>
/// 数据访问层代理实现类
/// </summary>
public class ORMHelper
{
//连接池的最大值和最小值(默认为1)
private const int MaxPool = 50;
public static List<Connection> ConnectionList = new List<Connection>(MaxPool);
public static Gateway GetGateway(DbTransaction trans)
{
Gateway gateway = null;
foreach (Connection conn in ConnectionList)
&n