【发布时间】:2012-03-26 16:23:41
【问题描述】:
这是我的 linq 查询
from row in (
from c in db.TabC
from cpd in db.TabPD
from slm in db.TabSLM
where cpd.SLid == slm.SLid
where c.Id == cpd.CID
where c.O_Id == 1
select new { c, cpd, slm })
group row in row.slm.SLType into g
select new
{
SLType = g.Key,
EStat = g.Count(r => r.c.EstatID != null),
Training = g.Count(r => r.cpd.TrId != null),
TrainingComplete =
g.Count(r => r.cpd.TrStat == 44),
AssessmentComplete =
g.Count(r => r.cpd.CndAssess == 44)
};
我需要对表 db.TabSLM 进行左连接,并获取与该表中一样多的记录。 TabC 是主表,TabSLM 也是。 TabPD 具有引用 TabC 和 TabSLM 的详细记录。使用此查询,当 TabPD 中没有针对 TabC rowid 或 TabSLM rowid 的匹配项时,我没有返回任何记录。我想要的是返回 TabSLM 中存在的记录数,以防没有匹配项。关于如何修改此查询的任何想法?
下面是三个表的示例数据,其中列出了最少的字段
TabC
ID O_ID Name
1 1 ABC
2 1 XYZ
3 1 RST
TabPD
RowID CID SLid
1 2 1
2 1 1
3 3 2
4 ...
TabSLM
SLid SLType
1 single level
2 Multi level
通过上面的查询,我可以获得 TabC.O_ID == 1 的记录,但不能获得 TabC.O_ID == 3 的记录,因为 TabC.O_ID 没有任何 ID == 3 的记录。我仍然想要显示 SLType,其他列显示为 0
感谢您的宝贵时间...
【问题讨论】:
标签: .net linq c#-4.0 entity-framework-4