NHibernate中数据操作封装类定义
来源:互联网 发布:软件发票备注栏规定 编辑:程序博客网 时间:2024/06/05 22:59
NHibernate中数据操作封装类定义
/// <summary> /// 定义:数据操作方法接口 /// vp:hsg /// create date:2013-08-29 /// </summary> /// <typeparam name="T"></typeparam> public interface IDataMethod<T> { ISessionFactory dbsf { get; } // bool Insert(T entity); bool Update(T entity); bool Delete(T entity); // bool DeleteList(IList<T> entityList); bool DeleteList(IList<T> entityList, ISession s); bool Delete(object id); // bool InsertOrUpdate(T entity); // T GetRecordByID(object id); IList<T> GetRecords(string whereStr); IList<T> GetRecordsALL(); } /// <summary> /// 默认的适配器类 /// 定义:抽象的数据操作方法 /// vp:hsg,wangjingbao /// create date:2013-08-29 /// </summary> /// <typeparam name="T"></typeparam> [Serializable()] public abstract class AbsDataMethod<T>:IDataMethod<T> { protected T _object; protected string _modelName = string.Empty; // #region IDataMethod<T> 成员 public ISessionFactory dbsf { get { return DBSessionFactory.SF; } } public virtual bool Insert(T entity) { bool rbc=false; using (ISession s = this.dbsf.OpenSession()) { s.Save(entity); s.Flush(); rbc=true; } return rbc; } public virtual bool Update(T entity) { bool rbc = false; using (ISession s = this.dbsf.OpenSession()) { s.Update(entity); s.Flush(); rbc = true; } return rbc; } public virtual bool Delete(T entity) { bool rbc = false; using (ISession s = this.dbsf.OpenSession()) { s.Delete(entity); s.Flush(); rbc = true; } return rbc; } public virtual bool DeleteList(IList<T> entityList) { bool rbc = false; using (ISession s = this.dbsf.OpenSession()) { foreach (T t in entityList) { s.Delete(t); } s.Flush(); rbc = true; } return rbc; } public virtual bool DeleteList(IList<T> entityList, ISession s) { bool rbc = false; foreach (T t in entityList) { s.Delete(t); } s.Flush(); rbc = true; return rbc; } public virtual bool Delete(object id) { bool rbc = false; T t = this.GetRecordByID(id); if (t != null) { this.Delete(t); rbc = true; } return rbc; } public virtual bool InsertOrUpdate(T entity) { bool rbc = false; using (ISession s = this.dbsf.OpenSession()) { s.SaveOrUpdate(entity); s.Flush(); rbc = true; } return rbc; } public virtual T GetRecordByID(object id) { using (ISession s = this.dbsf.OpenSession()) { return s.Get<T>(id); } } // protected string m_tableName=""; public virtual IList<T> GetRecords(string whereStr) { using (ISession s = this.dbsf.OpenSession()) { string sql = string.Format("select * from {0} {1}", m_tableName, whereStr); ISQLQuery sq = s.CreateSQLQuery(sql); return sq.List<T>(); } } public virtual IList<T> GetRecordsALL() { return this.GetRecords(""); } //--------------------- // public T Get(object id) { using (ISession s = this.dbsf.OpenSession()) { _object = s.Get<T>(id); return _object; } } public T Load(object id) { using (ISession s = this.dbsf.OpenSession()) { return s.Load<T>(id); } } public abstract object GetKey(T entity); public abstract IList<T> LoadALL(); public abstract IList<T> LoadList(object value); #endregion // } /// <summary> /// 定义一个父类接口 /// </summary> /// <typeparam name="C"></typeparam> public interface INHParent<C> { void AddChild(C child); IList<C> LoadChildren(); } /// <summary> /// 定义一个子类接口 /// </summary> /// <typeparam name="P"></typeparam> public interface INHChild<P> { P Parent { get; } }
0 0
- NHibernate中数据操作封装类定义
- Nhibernate 数据操作封装类 可以执行hql 原生sql 返回DataSet
- NHibernate中数据操作具体实例一例
- NHibernate中定义实体类属性的方法
- CC_SYNTHESIZE 类中声明定义数据 和操作该数据的函数
- CC_SYNTHESIZE 类中声明定义数据 和操作该数据的函数
- Delphi ADO数据操作封装类
- 封装JPA的数据操作DAO类
- JSP中对MySQL数据操作的封装
- 数据控制、定义、操作
- 数据操作的封装--sqlhelper
- Struts2封装数据的操作
- VB.NET 数据操作封装
- python3 数据操作简单封装
- 数据和操作的封装
- 类中const 数据成员的定义
- 企业库数据通用操作封装中的参数类
- Hibernate封装通用数据操作基类DAO
- [Unity3D]Unity3D游戏开发之史上最简单的鼠标点击控制人物走动实现
- 从页面选择文件到FTP上传(使用struts2框架)
- C语言,内存对齐,内存分配,地址操作,结构体(一)
- Android中获取联系人信息(一)
- 增加一块新硬盘,如何把它挂载到/home目录 从而扩大home空间
- NHibernate中数据操作封装类定义
- 在用户空间(和内核空间)访问内存的绝对地址
- 打造“神犇”是教育的未来吗?
- 老罗Android视频教学资源下载地址
- 在Eclipse中配置tomcat6详细步骤
- [JS]jquery cache-autocomplete
- 字符编码
- Android之SharedPreferences权限
- 黑马程序员------集合