Exemplo n.º 1
0
        /// <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();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 把集合转成字典形式
        /// </summary>
        /// <param name="lst">集合</param>
        /// <param name="mappingInfo">映射</param>
        /// <returns></returns>
        private static Dictionary <string, List <object> > GetEntityDictionary(IEnumerable lst, EntityMappingInfo mappingInfo)
        {
            Dictionary <string, List <object> > dic = new Dictionary <string, List <object> >();
            string propertyName = mappingInfo.PropertyName;

            List <object> lstCur = null;

            foreach (object obj in lst)
            {
                EntityBase entity = obj as EntityBase;
                if (entity == null)
                {
                    continue;
                }
                string key = mappingInfo.SourceProperty.GetValue(entity).ToString();
                if (!dic.TryGetValue(key, out lstCur))
                {
                    lstCur   = new List <object>();
                    dic[key] = lstCur;
                }
                lstCur.Add(entity);
                //创建子集合
                if (!mappingInfo.IsParent)
                {
                    object childlst = Activator.CreateInstance(mappingInfo.FieldType);
                    mappingInfo.SetValue(entity, childlst);
                    entity.OnFillChild(propertyName, new ScopeList());
                }
            }
            return(dic);
        }
Exemplo n.º 3
0
        /// <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);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 填充该列表的子类
        /// </summary>
        /// <param name="sender">发送者</param>
        public static void FillChildList(string propertyName, EntityBase sender)
        {
            Type              senderType   = CH.GetRealType(sender);                        //发送类的类型
            EntityInfoHandle  senderHandle = EntityInfoManager.GetEntityHandle(senderType); //获取发送类的信息
            EntityMappingInfo mappingInfo  = senderHandle.MappingInfo[propertyName];

            if (mappingInfo != null)
            {
                EntityPropertyInfo pkHandle = mappingInfo.SourceProperty;//获取实体主键属性句柄
                object             lst      = Activator.CreateInstance(mappingInfo.FieldType);
                mappingInfo.SetValue(sender, lst);
                object           pk          = pkHandle.GetValue(sender);
                EntityInfoHandle childHandle = mappingInfo.TargetProperty.BelongInfo;//获取子元素的信息
                FillChilds(pk, childHandle, mappingInfo, sender, propertyName);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// 清空父属性
 /// </summary>
 private string ClearParentProperty(EntityBase entity)
 {
     _mapInfo.SetValue(entity, null);
     entity._dicUpdateProperty___.Remove(_mapInfo.PropertyName);
     return(null);
 }