Ejemplo n.º 1
0
        internal CoreHelper.DBHelper GetDBHelper(DataAccessType accessType = DataAccessType.Default)
        {
            DBLocation.DataAccessType = accessType;
            var helper = SettingConfig.GetDbAccess(DBLocation);

            return(helper);
        }
Ejemplo n.º 2
0
        internal AbsDBExtend copyDBExtend()
        {
            var helper     = SettingConfig.GetDbAccess(dbContext.DBLocation);
            var dbContext2 = new DbContext(helper, dbContext.DBLocation);

            dbContext2.ShardingMainDataIndex = dbContext.ShardingMainDataIndex;
            dbContext2.UseSharding           = dbContext.UseSharding;
            return(DBExtendFactory.CreateDBExtend(dbContext2));
        }
Ejemplo n.º 3
0
        internal override DbContext GetDbContext()
        {
            if (SettingConfig.GetDbAccess == null)
            {
                throw new Exception("请配置CRL数据访问对象,实现CRL.SettingConfig.GetDbAccess");
            }
            var helper    = SettingConfig.GetDbAccess(dbLocation);
            var dbContext = new DbContext(helper, dbLocation);

            return(dbContext);
        }
Ejemplo n.º 4
0
        static DbContext getDbContext <T>()
        {
            var dbLocation = new CRL.DBLocation()
            {
                DataAccessType = DataAccessType.Default, ManageType = typeof(T)
            };
            var helper    = SettingConfig.GetDbAccess(dbLocation);
            var dbContext = new DbContext(helper, dbLocation);

            return(dbContext);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 仅用来检查表结构
 /// </summary>
 /// <returns></returns>
 DBExtend GetBackgroundDBExtend()
 {
     if (backgroundDBExtend == null)
     {
         var helper     = SettingConfig.GetDbAccess(dbContext.DBLocation);
         var dbContext2 = new DbContext(helper, dbContext.DBLocation);
         dbContext2.ShardingMainDataIndex = dbContext.ShardingMainDataIndex;
         dbContext2.UseSharding           = dbContext.UseSharding;
         backgroundDBExtend = new DBExtend(dbContext2);
     }
     return(backgroundDBExtend);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 数据访问对象[基本方法]
        /// 按指定的类型
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        protected DBExtend GetDbHelper(Type type)
        {
            if (SettingConfig.GetDbAccess == null)
            {
                throw new Exception("请配置CRL数据访问对象,实现CRL.SettingConfig.GetDbAccess");
            }
            CoreHelper.DBHelper helper = SettingConfig.GetDbAccess(type);
            var db = new DBExtend(helper);

            db.OnUpdateNotifyCacheServer = OnUpdateNotifyCacheServer;
            TypeCache.SetDBAdapterCache(typeof(TModel), db._DBAdapter);
            return(db);
        }
Ejemplo n.º 7
0
        internal override DbContext GetDbContext()
        {
            DbContext dbContext = null;

            ////cache = false;
            //string contextName = "DbContext." + GetType().Name;//同一线程调用只创建一次
            //var _BeginTransContext = CallContext.GetData<bool>(Base.CRLContextName);
            //if (_BeginTransContext)//对于数据库事务,只创建一个上下文
            //{
            //    contextName = "TransDbContext";
            //}

            //if (cache)
            //{
            //    dbContext = CallContext.GetData<DbContext>(contextName);
            //}
            //if (dbContext != null)
            //{
            //    return dbContext;
            //}
            if (SettingConfig.GetDbAccess == null)
            {
                throw new CRLException("请配置CRL数据访问对象,实现CRL.SettingConfig.GetDbAccess");
            }
            var helper = SettingConfig.GetDbAccess(dbLocation);

            //helper.Name = Guid.NewGuid().ToString();
            dbContext = new DbContext(helper, dbLocation);
            //if (cache)
            //{
            //    dbContext.Name = contextName;
            //    var allKey = "AllDbContext";
            //    var allList = Base.GetCallDBContext();
            //    CallContext.SetData(contextName, dbContext);
            //    allList.Add(contextName);
            //    CallContext.SetData(allKey, allList);
            //}
            return(dbContext);
        }