Exemplo n.º 1
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.º 2
0
        /// <summary>
        /// 更新子属性
        /// </summary>
        /// <param name="mapInfo"></param>
        private string UpdateChildProperty(EntityBase entity)
        {
            object parentObject = _mapInfo.GetValue(entity);
            object pkValue      = null;

            if (parentObject != null)
            {
                pkValue = _mapInfo.TargetProperty.GetValue(parentObject);//获取ID
            }
            else
            {
                pkValue = _mapInfo.SourceProperty.FieldType.IsValueType ? Activator.CreateInstance(_mapInfo.SourceProperty.FieldType) : null;
            }
            _mapInfo.SourceProperty.SetValue(entity, pkValue);
            return(_mapInfo.TargetProperty.PropertyName);
        }
Exemplo n.º 3
0
        /// <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();
            }
        }