批量获取子表数据- 肖峰- 博客园

        /// <summary>
        /// 获取一批产品的单位列表字典。
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        public Dictionary<int, List<ProductUnit>> GetProductUnitListDicByProductIdList(IList<int> ids)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select Id,Product_Id,UnitName,Conversion,IsDefaultUnit,IsBasicUnit,SortNo ");
            strSql.Append(" FROM T_Product_Unit ");
            if (ids != null && ids.Count > 0)
            {
                strSql.Append(" Where Product_Id in (");
                for (int i = 0; i < ids.Count; i++)
                {
                    strSql.Append(ids[i]);
                    strSql.Append(",");
                }
                strSql.Remove(strSql.Length - 1, 1);
                strSql.Append(")");
            }

            Dictionary<int, List<ProductUnit>> unitdic = new Dictionary<int, List<ProductUnit>>();
            _dbCommand = _database.GetSqlStringCommand(strSql.ToString());
            using (IDataReader reader = _database.ExecuteReader(_dbCommand))
            {
                while (reader.Read())
                {
                    ProductUnit pu = ReaderBind(reader);
                    List<ProductUnit> pus = null;
                    if (unitdic.TryGetValue(pu.ProductId, out pus) == false)
                    {
                        pus = new List<ProductUnit>();
                        unitdic[pu.ProductId] = pus;
                    }
                    pus.Add(pu);
                }
            }
            return unitdic;
        }

郑重声明:资讯 【批量获取子表数据- 肖峰- 博客园】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——