internal DBHelper GetDBHelper(DataAccessType accessType = DataAccessType.Default) { DBLocation.DataAccessType = accessType; var helper = SettingConfig.GetDBAccessBuild(DBLocation).GetDBHelper(); return(helper); }
internal CoreHelper.DBHelper GetDBHelper(DataAccessType accessType = DataAccessType.Default) { DBLocation.DataAccessType = accessType; var helper = SettingConfig.GetDbAccess(DBLocation); return(helper); }
internal override DbContext GetDbContext() { dbLocation.ManageName = ManageName; var helper = SettingConfig.GetDBAccessBuild(dbLocation).GetDBHelper(); var dbContext = new DbContext(helper, dbLocation); return(dbContext); }
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)); }
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); }
static DbContext getDbContext <T>(string manageName) { var dbLocation = new CRL.DBLocation() { DataAccessType = DataAccessType.Default, ManageType = typeof(T), ManageName = manageName }; var helper = SettingConfig.GetDBAccessBuild(dbLocation).GetDBHelper(); var dbContext = new DbContext(helper, dbLocation); return(dbContext); }
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); }
/// <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); }
/// <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); }
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); }
static void SetProperties(Attribute.TableAttribute table) { if (table.Fields.Count > 0) { return; } var type = table.Type; List <Attribute.FieldAttribute> list = new List <CRL.Attribute.FieldAttribute>(); var fieldDic = new IgnoreCaseDictionary <Attribute.FieldAttribute>(); //string fieldPat = @"^([A-Z][a-z|\d]+)+$"; int n = 0; Attribute.FieldAttribute keyField = null; #region 读取 var typeArry = table.Type.GetProperties().ToList(); //移除重复的 var dic = new Dictionary <string, PropertyInfo>(); foreach (PropertyInfo info in typeArry) { if (!dic.ContainsKey(info.Name)) { dic.Add(info.Name, info); } } foreach (PropertyInfo info in dic.Values) { //if (!System.Text.RegularExpressions.Regex.IsMatch(info.Name, fieldPat)) //{ // throw new CRLException(string.Format("属性名:{0} 不符合规则:{1}", info.Name, fieldPat)); //} //排除没有SET方法的属性 if (info.GetSetMethod() == null) { continue; } Type propertyType = info.PropertyType; Attribute.FieldAttribute f = new CRL.Attribute.FieldAttribute(); //排除集合类型 if (propertyType.FullName.IndexOf("System.Collections") > -1) { continue; } object[] attrs = info.GetCustomAttributes(typeof(Attribute.FieldAttribute), true); if (attrs != null && attrs.Length > 0) { f = attrs[0] as Attribute.FieldAttribute; } f.SetPropertyInfo(info); f.PropertyType = propertyType; f.MemberName = info.Name; f.TableName = table.TableName; f.ModelType = table.Type; if (!string.IsNullOrEmpty(f.VirtualField)) { if (SettingConfig.StringFormat != null) { f.VirtualField = SettingConfig.StringFormat(f.VirtualField); } f.VirtualField = f.VirtualField.Replace("$", "{" + type.FullName + "}");//虚拟字段使用Type名 } //排除不映射字段 if (!f.MapingField) { continue; } if (propertyType == typeof(System.String)) { if (f.Length == 0) { f.Length = 30; } } if (f.IsPrimaryKey)//保存主键 { table.PrimaryKey = f; f.FieldIndexType = Attribute.FieldIndexType.非聚集唯一; keyField = f; n += 1; } if (f.FieldType != Attribute.FieldType.关联字段) { fieldDic.Add(f.MemberName, f); } list.Add(f); } if (n == 0) { //throw new CRLException(string.Format("对象{0}未设置任何主键", type.Name)); } else if (n > 1) { throw new CRLException(string.Format("对象{0}设置的主键字段太多 {1}", type.Name, n)); } #endregion //主键排前面 if (keyField != null) { list.Remove(keyField); list.Insert(0, keyField); } table.Fields = list; table.FieldsDic = fieldDic; }