/// <summary> /// 填充字类列表 /// </summary> /// <param name="pks">ID集合</param> /// <param name="fatherInfo">父表对应类的信息</param> /// <param name="dicElement">元素</param> /// <param name="mappingInfo">当前父表对应属性的映射信息</param> private static void FillParent(object pk, EntityInfoHandle fatherInfo, EntityMappingInfo mappingInfo, string propertyName, EntityBase sender) { DBInfo db = fatherInfo.DBInfo; DataBaseOperate oper = fatherInfo.DBInfo.DefaultOperate; BQLDbBase dao = new BQLDbBase(oper); ScopeList lstScope = new ScopeList(); sender.OnFillParent(propertyName, lstScope); lstScope.AddEqual(mappingInfo.TargetProperty.PropertyName, pk); IDataReader reader = dao.QueryReader(lstScope, fatherInfo.EntityType); try { //获取子表的get列表 List <EntityPropertyInfo> lstParamNames = CacheReader.GenerateCache(reader, fatherInfo);//创建一个缓存数值列表 while (reader.Read()) { object newObj = fatherInfo.CreateSelectProxyInstance(); mappingInfo.SetValue(sender, newObj); CacheReader.FillObjectFromReader(reader, lstParamNames, newObj, db); } sender.OnPropertyUpdated(mappingInfo.PropertyName); } finally { reader.Close(); oper.AutoClose(); } }
/// <summary> /// 查询并填充子类信息 /// </summary> /// <param name="pks"></param> /// <param name="mappingInfo"></param> /// <param name="dicEntity"></param> /// <param name="dao"></param> /// <param name="lstParamNames"></param> /// <param name="db"></param> /// <param name="curObjs"></param> /// <param name="filter"></param> private static void FillChildReader(Queue <object> pks, EntityMappingInfo mappingInfo, Dictionary <string, List <object> > dicEntity, BQLDbBase dao, ref List <EntityPropertyInfo> lstParamNames, DBInfo db, Queue <object> curObjs, ScopeList filter) { EntityInfoHandle childInfo = mappingInfo.TargetProperty.BelongInfo; string fullName = mappingInfo.TargetProperty.BelongInfo.EntityType.FullName; Type childType = mappingInfo.TargetProperty.BelongInfo.EntityType; List <object> senders = null; while (pks.Count > 0) { Queue <object> searchPks = GetSearchPKs(pks); if (searchPks.Count <= 0) { break; } ScopeList lstScope = new ScopeList(); lstScope.AddScopeList(filter); lstScope.AddIn(mappingInfo.TargetProperty.PropertyName, searchPks); using (IDataReader reader = dao.QueryReader(lstScope, childInfo.EntityType)) { //获取子表的get列表 if (lstParamNames == null) { lstParamNames = CacheReader.GenerateCache(reader, childInfo);//创建一个缓存数值列表 } while (reader.Read()) { string fk = reader[mappingInfo.TargetProperty.ParamName].ToString(); if (!dicEntity.TryGetValue(fk, out senders)) { continue; } object obj = childInfo.CreateSelectProxyInstance(); if (curObjs != null) { curObjs.Enqueue(obj); } CacheReader.FillObjectFromReader(reader, lstParamNames, obj, db); foreach (object sender in senders) { if (mappingInfo.IsParent) { mappingInfo.SetValue(sender, obj); } else { IList lst = (IList)mappingInfo.GetValue(sender); lst.Add(obj); } } } } } }
/// <summary> /// 从Reader里边读取一个对象数据 /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="reader">reader</param> /// <returns></returns> public static T LoadFormReader <T>(IDataReader reader, EntityInfoHandle entityInfo) where T : EntityBase, new() { //string fullName = typeof(T).FullName; if (reader != null && !reader.IsClosed) { List <EntityPropertyInfo> lstParamNames = GenerateCache(reader, entityInfo); T ret = (T)entityInfo.CreateSelectProxyInstance();//实例化对象 FillObjectFromReader(reader, lstParamNames, ret, entityInfo.DBInfo); return(ret); } return(default(T)); }
/// <summary> /// 从Reader里边读取数据集合(快速) /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="reader">reader</param> /// <returns></returns> public static List <T> LoadFormReaderList <T>(IDataReader reader) where T : EntityBase, new() { EntityInfoHandle entityInfo = EntityInfoManager.GetEntityHandle(typeof(T)); List <T> retLst = new List <T>(); if (reader != null && !reader.IsClosed) { List <EntityPropertyInfo> lstParamNames = GenerateCache(reader, entityInfo); while (reader.Read()) { T obj = entityInfo.CreateSelectProxyInstance() as T; FillObjectFromReader(reader, lstParamNames, obj, entityInfo.DBInfo); retLst.Add(obj); } } return(retLst); }
/// <summary> /// 从Reader里边读取数据集合(快速,返回集合的大小) /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="reader">reader</param> /// <param name="entityInfo">实体类信息</param> /// <param name="totalSize">集合总大小</param> /// <returns></returns> public static List <T> LoadFormReaderList <T>(IDataReader reader, EntityInfoHandle entityInfo, out int totalSize) where T : EntityBase, new() { List <T> retLst = new List <T>(); totalSize = 0;//初始化当前记录集总大小 if (reader != null && !reader.IsClosed) { List <EntityPropertyInfo> lstParamNames = GenerateCache(reader, entityInfo); while (reader.Read()) { T obj = (T)entityInfo.CreateSelectProxyInstance(); int curSize = 0; //获取当前值大小 FillObjectFromReader(reader, lstParamNames, obj, out curSize); totalSize += curSize; //加到当前记录总大小里边 retLst.Add(obj); } } return(retLst); }
/// <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); }
/// <summary> /// 填充字类列表 /// </summary> /// <param name="pks">ID集合</param> /// <param name="childHandle">子元素的信息句柄</param> /// <param name="mappingInfo">映射信息</param> /// <param name="dicElement">元素</param> private static void FillChilds(object pk, EntityInfoHandle childHandle, EntityMappingInfo mappingInfo, EntityBase sender, string propertyName) { EntityInfoHandle childInfo = mappingInfo.TargetProperty.BelongInfo; DBInfo db = childInfo.DBInfo; DataBaseOperate oper = childHandle.DBInfo.DefaultOperate; BQLDbBase dao = new BQLDbBase(oper); ScopeList lstScope = new ScopeList(); sender.OnFillChild(propertyName, lstScope); lstScope.AddEqual(mappingInfo.TargetProperty.PropertyName, pk); IDataReader reader = dao.QueryReader(lstScope, childInfo.EntityType); try { string fullName = mappingInfo.TargetProperty.BelongInfo.EntityType.FullName; Type childType = mappingInfo.TargetProperty.BelongInfo.EntityType; //获取子表的get列表 List <EntityPropertyInfo> lstParamNames = CacheReader.GenerateCache(reader, childInfo);//创建一个缓存数值列表 IList lst = (IList)mappingInfo.GetValue(sender); while (reader.Read()) { object obj = childInfo.CreateSelectProxyInstance(); //string fk = reader[mappingInfo.TargetProperty.ParamName].ToString(); CacheReader.FillObjectFromReader(reader, lstParamNames, obj, db); lst.Add(obj); } } finally { reader.Close(); oper.AutoClose(); } }