public int SaveChanges() { //1.根据配置文件内容 创建 DBSessionFactory 工厂对象 IDAL.IDbSessionFactory sessionFactory = null; //2.通过 工厂 创建 DBSession对象 IDAL.IDbSession iDbSession = sessionFactory.GetDbSession(); return(iDbSession.SaveChanges()); }
public IDAL.IDbSession GetDbSession() { //从当前线程中 获取 DBContext 数据仓储 对象 IDAL.IDbSession dbSesion = CallContext.GetData(typeof(DbSessionFactory).Name) as IDAL.IDbSession; if (dbSesion == null) { dbSesion = new DbSession(); CallContext.SetData(typeof(DbSessionFactory).Name, dbSesion); } return(dbSesion); }
//依赖接口编程,尽量返回给外界抽象的东西 public IDbSession GetDbSession() { IDAL.IDbSession dbSession = CallContext.GetData("DbSession") as DbSession; int threadId1 = Thread.CurrentThread.ManagedThreadId; if (dbSession == null) { dbSession = new DAL.DbSession(); CallContext.SetData("DbSession", dbSession); } return(dbSession); }