【发布时间】:2011-05-25 21:05:22
【问题描述】:
我无法提出高效的 LINQ-to-SQL 查询。我正在尝试做这样的事情:
from x in Items
select new
{
Name = x.Name
TypeARelated = from r in x.Related
where r.Type == "A"
select r
}
如您所料,它会从“Items”表生成一个查询,并在“Related”表上进行左连接。现在,如果我再添加几行类似的行...
from x in Items
select new
{
Name = x.Name
TypeARelated = from r in x.Related
where r.Type == "A"
select r,
TypeBRelated = from r in x.Related
where r.Type == "B"
select r
}
结果是运行与第一次尝试类似的查询,然后对“项目”中的每条记录的“相关”表进行单独查询。有没有办法将这一切都包含在一个查询中?这会是什么原因?提前感谢您提供的任何帮助。
【问题讨论】:
标签: c# .net sql linq linq-to-sql