关闭

ADO.NET快速上手实践总结(下)

发表于:2010-8-19 10:38

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:Jeff Wong(cnblogs)    来源:51Testing软件测试网采编

  四、实现伪SqlMapper

  1、BaseMapper类

using System;  using System.Collections.Generic; 
using System.Data; 
using System.Data.Common; 
using System.Data.SqlClient; 
namespace AdoNetDataAccess.Mapper 
{
    using AdoNetDataAccess.Core.Contract;
    public abstract class BaseMapper
    {
        public IDbOperation CurrentDbOperation;
        #region query for list
        public abstract IList<T> QueryForList<T>(string sqlStr)
  where T : class, new();
        public abstract IList<T> QueryForList<T>(string sqlStr, Type objType)  where T : class, new();  public abstract IList<T> QueryForList<T>(string sqlStr, CommandType cmdType, List<DbParameter> listParams) 
       where T : class, new();
        public abstract IList<T> QueryForList<T>
(string sqlStr, CommandType cmdType, List<DbParameter> listParams, Type objType) 
       where T : class, new();
       #endregion
       #region query for dictionary
       public abstract IDictionary<K, T> QueryForDictionary<K, T>(string key, string sqlStr)
            where T : class, new();
        public abstract IDictionary<K, T> QueryForDictionary<K, T>(string key, string sqlStr, Type objType)
    where T : class, new();
        public abstract IDictionary<K, T> QueryForDictionary<K, T>
(string key, string sqlStr, CommandType cmdType, Type objType)
            where T : class, new();
        public abstract IDictionary<K, T> QueryForDictionary<K, T>
(string key, string sqlStr, CommandType cmdType, List<DbParameter> listParams, Type objType)
                    where T : class, new();
        #endregion
        #region dataset datatable
        public abstract DataTable FillDataTable(string sqlStr, CommandType cmdType, List<DbParameter> listParams);
        public abstract DataSet FillDataSet(string sqlStr, CommandType cmdType, List<DbParameter> listParams);
        #endregion
        #region ExecuteScalar
        public abstract object ExecuteScalar(string sqlStr, CommandType cmdType, List<DbParameter> listParams);
        #endregion
        #region insert
        public abstract int Insert(string sqlStr);
        public abstract int Insert(string sqlStr, CommandType cmdType, List<DbParameter> listParams);  
        public abstract bool BatchInsert(string tableName, int batchSize, int copyTimeout, DataTable dt);
        #endregion
        #region delete
        public abstract int Delete(string sqlStr);
        public abstract int Delete(string sqlStr, CommandType cmdType, List<DbParameter> listParams);   
        #endregion
        #region update
        public abstract int Update(string sqlStr);
        public abstract int Update(string sqlStr, CommandType cmdType, List<DbParameter> listParams);   
        #endregion
    }
}

  上面代码中的方法您是不是很熟悉呢? 呵呵,使用IBatis.net 的童鞋应该会和楼猪产生更多的共鸣。

61/6123456>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号