/// <summary> /// 关联表 /// </summary> /// <param name="from"></param> /// <param name="sourceTable"></param> /// <param name="targetTable"></param> /// <returns></returns> private KeyWordFromItem InnerTable(KeyWordFromItem from, AliasTableMapping sourceTable) { KeyWordFromItem inner = from; string sTableName = sourceTable.TableInfo.GetAliasName(); foreach (KeyValuePair <string, AliasTableMapping> tablePair in sourceTable.ChildTables) { AliasTableMapping tTable = tablePair.Value; string tTableName = tTable.TableInfo.GetAliasName(); EntityMappingInfo minfo = tTable.MappingInfo; BQLCondition fhandle = null; //if (minfo.IsPrimary) //{ fhandle = BQL.Tables[sTableName][minfo.SourceProperty.ParamName] == BQL.Tables[tTableName][minfo.TargetProperty.ParamName]; //} //else //{ // fhandle = BQLDbBase.BQL.Tables[sTableName][minfo.SourceProperty.ParamName] == BQLDbBase.BQL.Tables[tTableName][minfo.PrimaryKey]; //} inner = inner.LeftJoin(tablePair.Value.TableInfo, fhandle); if (tTable.ChildTables.Count > 0) { inner = InnerTable(inner, tTable); } } return(inner); }
public TableAliasNameManager(BQLEntityTableHandle pEntityinfo) { _primaryTable = new AliasTableMapping(pEntityinfo, this, null); string key = pEntityinfo.GetEntityKey(); _dicKeyTable[key] = _primaryTable; }
/// <summary> /// 查找所属的表映射信息 /// </summary> /// <returns></returns> private AliasTableMapping FindMapping(BQLEntityTableHandle table) { AliasTableMapping ret = null; string key = table.GetEntityKey(); _dicKeyTable.TryGetValue(key, out ret); return(ret); }
/// <summary> /// 输出别名表 /// </summary> /// <param name="paramHandle"></param> /// <returns></returns> public string GetTableAliasName(BQLEntityTableHandle table) { AliasTableMapping mapping = FindMapping(table); if (mapping != null) { return(mapping.TableInfo.GetAliasName()); } return(null); }
/// <summary> /// 获取子类的字段信息 /// </summary> /// <param name="table"></param> private void LoadChildParams(AliasTableMapping table, List <BQLParamHandle> lst) { foreach (KeyValuePair <string, AliasTableMapping> cTableMapping in table.ChildTables) { AliasTableMapping cTable = cTableMapping.Value; lst.AddRange(cTable.GetParamInfo("*")); if (cTable.ChildTables.Count > 0) { LoadChildParams(cTable, lst); } } }
/// <summary> /// 添加子表 /// </summary> /// <param name="table">子表</param> public AliasTableMapping AddChildTable(BQLEntityTableHandle table) { AliasTableMapping retTable = null; Stack <BQLEntityTableHandle> stkTables = new Stack <BQLEntityTableHandle>(); BQLEntityTableHandle curTable = table; do { stkTables.Push(curTable); curTable = curTable.GetParentTable(); } while (!CommonMethods.IsNull(curTable)); AliasTableMapping lastTable = null;//上一个表 while (stkTables.Count > 0) { BQLEntityTableHandle cTable = stkTables.Pop(); string pName = cTable.GetPropertyName(); if (string.IsNullOrEmpty(pName)) { lastTable = this; retTable = this; } else { if (!lastTable._dicChildTables.ContainsKey(pName)) { EntityInfoHandle entityInfo = retTable.EntityInfo; EntityMappingInfo mapInfo = entityInfo.MappingInfo[pName]; if (mapInfo != null) { retTable = new AliasTableMapping(cTable, _belongManager, mapInfo); lastTable._dicChildTables[pName] = retTable; lastTable = retTable; } else { throw new MissingMemberException("实体:" + entityInfo.EntityType.FullName + "中找不到属性:" + pName + ""); } } else { retTable = lastTable._dicChildTables[pName]; lastTable = retTable; } } } return(retTable); }
/// <summary> /// 读取信息 /// </summary> /// <param name="reader"></param> /// <returns></returns> public EntityBase LoadFromReader(IDataReader reader) { IDBAdapter dbAdapter = _entityInfo.DBInfo.CurrentDbAdapter; EntityBase objRet = null; objRet = _entityInfo.CreateSelectProxyInstance() as EntityBase; foreach (AliasReaderMapping readMapping in _lstReaderMapping) { int index = readMapping.ReaderIndex; EntityPropertyInfo info = readMapping.PropertyInfo; if (!reader.IsDBNull(index)) { dbAdapter.SetObjectValueFromReader(reader, index, objRet, info, readMapping.NeedChangeType); } } foreach (KeyValuePair <string, AliasTableMapping> keyPair in _dicChildTables) { AliasTableMapping childMapping = keyPair.Value; object child = childMapping.LoadFromReader(reader); if (childMapping.MappingInfo.IsParent) { childMapping.MappingInfo.SetValue(objRet, child); } //else if ((!childMapping.MappingInfo.IsParent) && (child != null)) //{ // IList lst = childMapping.MappingInfo.GetValue(objRet) as IList; // if (lst == null) // { // lst = Activator.CreateInstance(childMapping.MappingInfo.FieldType) as IList; // childMapping.MappingInfo.SetValue(objRet, lst); // } // lst.Add(child); //} } return(objRet); }