【发布时间】:2016-07-08 01:54:50
【问题描述】:
我有这个模型
public class CPMC
{
public int CPMCId { get; set; }
public List<TPM> tpm = new List<TPM>();
public List<TPMC> tpmc = new List<TPMC>();
}
public class TPMC
{
public int Id { get; set; }
public Int64 Amount { get; set; }
public int PId { get; set; }
public Int64 PAmount { get; set; }
public int CPMCId { get; set; }
}
public class TPM
{
public int Type { get; set; }
public int Id { get; set; }
public Int64 Amount { get; set; }
public int VAT { get; set; }
public DateTime FromDate { get; set; }
public DateTime ToDate { get; set; }
public int CPMCId { get; set; }
}
这个List的数据是CPMCId的5k条记录,里面每个子list有50k条记录,条件是
List<int> CPMCIdList = aPP.Select(x => Convert.ToInt32(x.CPMCId)).Distinct().ToList();
List<CPMC> cpl = (from ap in CPMCIdList
select new CPMC
{
CPMCId = ap,
tpm = tpml.Where(x=>x.CPMCId == ap).ToList(),
tpmc = tpmcl.Where(x=>x.CPMCId == ap).ToList()
}).ToList();
但是在List中填充数据需要很多时间。你们可以为这个解决方案提供更好的实施吗 提前致谢
【问题讨论】:
-
您没有使用EntityFramework,而只是使用linq?鉴于结构和大量数据,我预计它会很慢,因为您将所有内容都放在内存中(每个子列表的 5k CPMCId 和 50k 记录)
-
是的,我正在使用简单的 linq 查询。我该怎么做才能让它更快
-
什么是 tmpl 和 tpmcl,为什么它们不是由 hashmap 支持的 IDictionary
(例如 Dictionary)? -
@moreON 那是 2 个子类分开然后他们不是
标签: c# performance linq optimization