コード例 #1
0
ファイル: DataAccessCommon.cs プロジェクト: radtek/buffalobro
        /// <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);
                            }
                        }
                    }
                }
            }
        }