您目前尚未登陆,请选择【登陆】或【注册
首页->全站代码->逐迹内容管理系统AspxNuke v2.0源码>>Common/NHibernate/BaseDAL.cs>>代码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:逐迹内容管理系统AspxNuke v2.0源码


当前文件路径:AspxNuke/Common/NHibernate/BaseDAL.cs 文件类型
普通视图
		            
1using System.Collections.Generic; 2using NHibernate; 3using System.Text; 4 5namespace AspxNuke.NH 6{ 7 /// <summary> 8 /// 数据层基类 9 /// </summary> 10 /// <typeparam name="T">实体类型</typeparam> 11 public class BaseDAL<T> : IBaseDAL<T> 12 { 13 /// <summary> 14 /// 新增记录 15 /// </summary> 16 /// <param name="t">实体</param> 17 public virtual void Insert(T t) 18 { 19 ISession session = NHibernateHelper.GetCurrentSession(); 20 ITransaction tx = null; 21 try 22 { 23 tx = session.BeginTransaction(); 24 25 session.Save(t); 26 _getIdentity = (int)session.GetIdentifier(t); 27 session.Flush(); 28 29 tx.Commit(); 30 } 31 catch (HibernateException ex) 32 { 33 if (tx != null) tx.Rollback(); 34 throw ex; 35 } 36 finally 37 { 38 NHibernateHelper.CloseSession(); 39 } 40 } 41 42 /// <summary> 43 /// 更新记录 44 /// </summary> 45 /// <param name="t">实体</param> 46 public virtual void Update(T t) 47 { 48 ISession session = NHibernateHelper.GetCurrentSession(); 49 ITransaction tx = null; 50 try 51 { 52 tx = session.BeginTransaction(); 53 54 session.Update(t); 55 session.Flush(); 56 57 tx.Commit(); 58 } 59 catch (HibernateException ex) 60 { 61 if (tx != null) tx.Rollback(); 62 throw ex; 63 } 64 finally 65 { 66 NHibernateHelper.CloseSession(); 67 } 68 } 69 70 /// <summary> 71 /// 删除记录 72 /// </summary> 73 /// <param name="t">实体</param> 74 public virtual void Delete(T t) 75 { 76 ISession session = NHibernateHelper.GetCurrentSession(); 77 ITransaction tx = null; 78 try 79 { 80 tx = session.BeginTransaction(); 81 82 session.Delete(t); 83 session.Flush(); 84 85 tx.Commit(); 86 } 87 catch (HibernateException ex) 88 { 89 if (tx != null) tx.Rollback(); 90 throw ex; 91 } 92 finally 93 { 94 NHibernateHelper.CloseSession(); 95 } 96 } 97 98 /// <summary> 99 /// 获取记录 100 /// </summary> 101 /// <param name="id">主键</param> 102 /// <returns>记录</returns> 103 public virtual T GetObject(int id) 104 { 105 ISession session = NHibernateHelper.GetCurrentSession(); 106 ITransaction tx = null; 107 try 108 { 109 tx = session.BeginTransaction(); 110 111 T t = (T)session.Get(typeof(T), id); 112 113 tx.Commit(); 114 115 return t; 116 } 117 catch (HibernateException ex) 118 { 119 if (tx != null) tx.Rollback(); 120 throw ex; 121 } 122 finally 123 { 124 NHibernateHelper.CloseSession(); 125 } 126 } 127 获取记录集合 261 262 private int _getRowCount; 263 /// <summary> 264 /// 获取记录行数,只有分页时有数值,其它为0 265 /// </summary> 266 public int GetRowCount 267 { 268 get { return _getRowCount; } 269 } 270 271 private int _getIdentity; 272 /// <summary> 273 /// 获取主键 274 /// </summary> 275 public int GetIdentity 276 { 277 get { return _getIdentity; } 278 } 279 } 280} 281
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:逐迹内容管理系统AspxNuke v2.0源码

- CocowoBlog V2.0修正版源码

- 武汉某培训机构全站代码

- AjaxPro.NET实现TextBox智能..

- 四酷全书简单新闻发布系统源码