/// <summary> /// 初始化数据库 /// </summary> public static void InitDB() { //if (_isInit) //{ // return; //} Type type = typeof(T); DataAccessLoader.AppendModelAssembly(type.Assembly); DataAccessLoader.InitConfig(); _db = GetDB(); Type baseType = typeof(BQLEntityTableHandle); PropertyInfo[] infos = type.GetProperties(BindingFlags.Public | BindingFlags.Static); foreach (PropertyInfo info in infos) { Type objType = info.PropertyType; if (!objType.IsSubclassOf(baseType)) { continue; } BQLEntityTableHandle handle = FastValueGetSet.GetGetMethodInfo(info.Name, type).Invoke(null, new object[] { }) as BQLEntityTableHandle; AddToDB(handle); } StaticConnection.ClearCacheOperate(_db); #if DEBUG _db.SqlOutputer.OnOutputerCreate += new Buffalo.DB.MessageOutPuters.CreateOutputerHandle(SqlOutputer_OnOutputerCreate); #endif }
/// <summary> /// 查找实体的关联属性信息属性 /// </summary> /// <param name="propertyName"></param> /// <returns></returns> public BQLEntityTableHandle FindChildEntity(string propertyName) { BQLEntityTableHandle table = null; PropertyInfoHandle handle = FastValueGetSet.GetPropertyInfoHandle(propertyName, this.GetType()); if (!handle.HasGetHandle) { throw new MissingMemberException("不存在属性:" + propertyName); } table = handle.GetValue(this) as BQLEntityTableHandle; return(table); }
private BQLEntityTableHandle _belongTable;//父表 /// <summary> /// 实体属性信息 /// </summary> /// <param name="entityInfo">实体信息</param> /// <param name="propertyName">属性名</param> internal BQLEntityParamHandle(EntityInfoHandle entityInfo, string propertyName, BQLEntityTableHandle belongTable) { this.entityInfo = entityInfo; if (propertyName != "*") { pinfo = entityInfo.PropertyInfo[propertyName]; if (pinfo == null) { throw new MissingMemberException(entityInfo.EntityType.FullName + "类中不包含属性:" + propertyName); } this._valueDbType = pinfo.SqlType; } _belongTable = belongTable; }
internal override string DisplayValue(KeyWordInfomation info) { //if (info.Infos.IsPutPropertyName && !info.IsWhere) //{ // return DisplayDataSetValue(info); //} IDBAdapter idba = info.DBInfo.CurrentDbAdapter; StringBuilder sbRet = new StringBuilder(); BQLEntityTableHandle outputTable = _belongTable; if (string.IsNullOrEmpty(entityInfo.TableName)) { outputTable = info.FromTable; } if (info.Infos.IsShowTableName) { if (info.AliasManager != null && !CommonMethods.IsNull(outputTable)) { string aliasName = info.AliasManager.GetTableAliasName(outputTable); if (!string.IsNullOrEmpty(aliasName)) { sbRet.Append(idba.FormatTableName(aliasName)); sbRet.Append("."); } } else if (!string.IsNullOrEmpty(entityInfo.TableName)) { sbRet.Append(idba.FormatTableName(entityInfo.TableName)); sbRet.Append("."); } } if (pinfo == null)//查询全部字段时候 { sbRet.Append("*"); } else { sbRet.Append(idba.FormatParam(pinfo.ParamName)); } return(sbRet.ToString()); }
/// <summary> /// 设置所属的实体的信息 /// </summary> /// <param name="entityInfo">实体信息</param> /// <returns></returns> protected void SetEntityInfo(EntityInfoHandle entityInfo, BQLEntityTableHandle parentTable, string propertyName) { _entityInfo = entityInfo; _parentTable = parentTable; _propertyName = propertyName; if (string.IsNullOrEmpty(propertyName)) { _entityKey = entityInfo.EntityType.Name; } else { if (!CommonMethods.IsNull(parentTable)) { StringBuilder sb = new StringBuilder(50); sb.Append(parentTable.GetEntityKey()); sb.Append("."); sb.Append(propertyName); _entityKey = sb.ToString(); } } }
/// <summary> /// 查找实体属性 /// </summary> /// <param name="propertyName"></param> /// <returns></returns> public BQLEntityParamHandle FindParamHandle(string propertyName) { string[] strpNames = propertyName.Split('.'); BQLEntityTableHandle currentTable = this; for (int i = 0; i < strpNames.Length; i++) { if (i == strpNames.Length - 1) { return(currentTable.FindParam(strpNames[i])); } else { currentTable = FindChildEntity(strpNames[i]); if (CommonMethods.IsNull(currentTable)) { throw new MissingMemberException("不存在属性:" + strpNames[i]); } } } return(null); }
public BQLEntityTableHandle(EntityInfoHandle entityInfo, BQLEntityTableHandle parentTable, string propertyName) { SetEntityInfo(entityInfo, parentTable, propertyName); }
public BQLEntityTableHandle(Type entityType, BQLEntityTableHandle parentTable, string propertyName) { SetEntityInfo(EntityInfoManager.GetEntityHandle(entityType), parentTable, propertyName); }
/// <summary> /// 添加到库信息 /// </summary> /// <param name="table"></param> /// <returns></returns> protected static BQLEntityTableHandle AddToDB(BQLEntityTableHandle table) { _db.AddToDB(table); return(table); }