我面临一个DefaultIfEmpty()
导致响应缓慢的问题。代码如下:
rslt = (
from p in P.Where(p => p.fcode == fCode && p.year == year && p.is_deleted == false && p.pname != pNameS)
from c in C.Where(c => c.fcode == fCode && c.ccode == p.ccode)
from pf in PF.Where(pf => pf.fcode == fCode && pf.pcode == p.pcode).DefaultIfEmpty()
from defHU in DEF.Where(def => def.fixed_key == Constants.HU && pf.hu == def.def_key).DefaultIfEmpty()
from defAU in DEF.Where(def => def.fixed_key == Constants.AU && pf.pau == def.def_key).DefaultIfEmpty()
select new PPShow{
Year = p.year,
PCode = p.pcode,
PName = p.production_name,
FCode = pf.fcode,
Br = p.br,
CName = c.cname,
PArea = pf.parea,
PAU = pf.pau,
PAUName = defAU.def_data,
HA = pf.ha,
HUName = defHU.def_data,
SDate = p.sdate,
PDate = p.pdate,
StartDate = p.start_date,
EndDate = p. end_date,
Flag = 1
}).ToList();
我尝试查询 10,000 条记录,大约需要 8.5 秒才能完成,而如果我删除所有DefaultIfEmpty()
.
我想知道DefaultIfEmpty()
实际上是做什么的。另外,我的情况有什么解决办法吗?