在应用程序中,我需要显示每个状态(来自)的客户、产品、{在此处插入其他实体}(来自、等)的数量(计数)。db.Custmers
db.Products
db.Geodata
结果可能看起来像
Customers: { Status = "OK", Count = 59 } { Status = "INVALID", Count = 14 } { Status = "NO_RESULT", Count = 29 } Products: { Status = "OK", Count = 541 } { Status = "INVALID", Count = 33 } { Status = "NO_RESULT", Count = 42 }
所以我写了一个查询......
from customer in db.Kunden
join pin in db.Geodata
on customer.AdressNr equals pin.AdressNr
group customer by pin.Status
into groups
select new {Status = groups.Key, Count = groups.Count()};
还有一个……
from product in db.Products
join pin in db.Geodata
on product.AdressNr equals pin.AdressNr
group product by pin.Status
into groups
select new {Status = groups.Key, Count = groups.Count()};
还有更多。他们工作得很好。但是我正在努力将它们全部集成到一个查询中(从而合并重复的部分,即最后两行)。
我怎样才能做到这一点?
编辑:谁能帮我改进这个问题?是否缺少任何关键信息?这是太本地化了,还是太宽泛了?