的操作,既然我们这里要降低耦合,那么根据我们前面的面向对象的设计原则与规范知道,我们推荐使用面向接口的编程的方式,来尽量的降低耦合性。我们来看看具
体的代码。首先我们定义一个通用的数据访问层的接口。
- /// <summary>
- /// 数据访问层统一接口
- /// </summary>
- public interface IDALInterface
- {
- //CUD 持久化操作
- /// <summary>
- /// 创建新的对象
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- int Create(object model);
- /// <summary>
- /// 更新对象
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- int Update(object model);
- /// <summary>
- /// 删除对象
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- int Delete(object model);
- //R 查询服务
- /// <summary>
- /// 查询所有记录
- /// </summary>
- /// <typeparam name="T">泛型模型</typeparam>
- /// <returns></returns>
- IList<T> GetAll<T>() where T : class,new();
- /// <summary>
- /// 查询满足条件的集合
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="whereCondition"></param>
- /// <returns></returns>
- IList<T> GetListByQuery<T>(WhereCondition whereCondition) where T : class,new();
- /// <summary>
- /// 返回总行数
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <returns></returns>
- int GetCount<T>();
- /// <summary>
- /// 返回满足条件的总行数
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="whereCondition"></param>
- /// <returns></returns>
- int GetCount<T>(WhereCondition whereCondition);
- /// <summary>
- /// 根据主键返回对象模型
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="key"></param>
- /// <returns></returns>
- T GetModelByKey<T>(object key) where T : class,new();
- //事务
- /// <summary>
- /// 是否事务执行
- /// </summary>
- bool IsTransaction
- {
- get;
- }
- /// <summary>
- /// 开始事务
- /// </summary>
- void BeginTransaction();
- /// <summary>
- /// 提交事务
- /// </summary>
- void Commit();
- /// <summary>
- /// 回滚事务
- /// </summary>
- void Rollback();
- }
这