多年了,想把自己的开发中的心得记录下来.今天我终于下笔了.............................
这些技术虽然已经有了很多的替代品(上层的框架实现),但本质的东西是没有变化,记录下来,以备以后参考吧,也是对刚入门的程序员的一种帮助.
前提:为了简化ADO.NET操作,地层采用了PetShop的SqlHelper的代码,当然,SqlHelper的这些代码还是比较简单的,关于SqlHelper的代码内容,这里不赘述了。
一、接口定义
using System; namespace AccpORM { /// <summary> /// 上层接口(独立于具体数据库的) /// </summary> interface IDbAccessTemplate { object ChargeValue<T>(System.Reflection.PropertyInfo pro, T obj); int Delete<T>(T obj); AccpORM.PaginationInfo DoPagination(AccpORM.PaginationInfo pi); AccpORM.PageInfo<T> DoPagination<T>(AccpORM.PageInfo<T> pi) where T : new(); AccpORM.PaginationInfo DoPagination(AccpORM.PaginationInfo pi, params string[] tbnames); System.Collections.Generic.List<T> EncapReaderToEntity<T>(System.Data.SqlClient.SqlDataReader reader) where T : new(); System.Collections.Generic.List<object> EncapReaderToEntity(Type entityClass, System.Data.SqlClient.SqlDataReader reader); int ExecuteNonQuery(System.Data.Common.DbTransaction ts, string sql); int ExecuteNonQuery(string sql); System.Collections.Generic.List<T> ExecuteQuery<T>(System.Data.Common.DbTransaction ts, string sql) where T : new(); System.Collections.Generic.List<T> ExecuteQuery<T>(string sql) where T : new(); string ExecuteScalar(System.Data.Common.DbTransaction ts, string sql); System.Collections.Generic.List<T> FindAll<T>(string tableName) where T : new(); System.Collections.Generic.List<T> FindAll<T>() where T : new(); T FindById<T>(object oid) where T : new(); T FindById<T>(string tableName, object oid) where T : new(); System.Collections.Generic.List<object> FindByProperty(Type entityClass, string libName, System.Collections.Generic.KeyValuePair<string, object> kvp); System.Collections.Generic.List<T> FindByProperty<T>(System.Collections.Generic.KeyValuePair<string, object> kvp) where T : new(); System.Reflection.PropertyInfo FindProName<T>(string Name); System.Reflection.PropertyInfo FindProName<T>(string Name, T obj); T FindUniqueResult<T>() where T : new(); System.Data.DbType GetDbType(System.Reflection.PropertyInfo pro); T GetEntity<T>(T obj, string PkPlace); T GetEntity<T>(T obj); int GetMaxRecodeCount(AccpORM.PaginationInfo pi); int GetMaxRecodeCount<T>(AccpORM.PageInfo<T> pi); int GetMaxRecodeCount<T>(AccpORM.Connditon[] Conditions, string PkPlace); int GetMaxRecodeCount(AccpORM.PaginationInfo pi, params string[] tbnames); int GetMaxRecodeCount<T>(AccpORM.Connditon[] Conditions); int GetMaxRecodeCount<T>(string tableName, AccpORM.Connditon[] Conditions); string GetNextOrderNum(string tableName, long volumeCode); string GetParname(AccpORM.Connditon con); string GetPrimaryKey(string tableName); string GetPrimaryKey<T>(string tableName); string GetPrimaryKey<T>(); string GetPrimaryKey(Type type); long GetVolumeCodeByArchiveSign(string tableName, string archiveSign); int Insert<T>(T obj); int InsertWithOutDefault<T>(T obj); int InsertWithPK<T>(T obj); void Merge<T>(System.Data.Common.DbTransaction ts, string tableName, T t); void Merge<T>(string tableName, T t); void Persist<T>(T t); void Persist<T>(System.Data.Common.DbTransaction ts, string tableName, T t); void Persist<T>(string tableName, T t); void Persist(System.Data.Common.DbTransaction ts, string tableName, object t); void PersistWithPK<T>(T t) where T : new(); int Remove<T>(System.Data.Common.DbTransaction ts, string tableName, T obj); void Remove(System.Data.Common.DbTransaction ts, string tableName, System.Collections.Generic.List<object> oidList); void Remove(string tableName, System.Collections.Generic.List<object> oidList); System.Collections.Generic.List<T> Select<T>(int pageIndex, int countPerPage, AccpORM.Connditon[] Conditions) where T : new(); System.Collections.Generic.List<T> Select<T>(int pageIndex, int countPerPage, AccpORM.Connditon[] Conditions, string OrderPlace, bool IsDesc, string PkPlace) where T : new(); System.Collections.Generic.List<T> Select<T>(string tableName, int pageIndex, int countPerPage, AccpORM.Connditon[] Conditions) where T : new(); System.Collections.Generic.List<T> Select<T>(int pageIndex, int countPerPage, AccpORM.Connditon[] Conditions, string PkPlace) where T : new(); System.Collections.Generic.List<T> Select<T>(string tableName, int pageIndex, int countPerPage, AccpORM.Connditon[] Conditions, string OrderPlace) where T : new(); System.Collections.Generic.List<T> Select<T>(int pageIndex, int countPerPage, AccpORM.Connditon[] Conditions, string OrderPlace, bool IsDesc) where T : new(); int Update<T>(T obj); } }