给定具有外连接的LINQ to Entity查询...
var query = from items in entityDb.TableName
join requestedBy in entityDb.People on items.RequestedById equals requestedBy.PersonId into requestedByOuter
from requestedBy in requestedByOuter.DefaultIfEmpty()
select items;
这种外连接的编译(Lamba表达式)版本是什么样的?有没有办法在visual studio调试器中看到这个?
更新
为了澄清,Jon Skeet在他的book中解释说,在进行“真正的编译”之前,查询表达式是“编译器翻译”到普通的C#代码。我的问题是如何在外连接的情况下将查询表达式转换为真正的C#?而且,我们可以在调试器中或通过其他方式看到这些翻译吗?
答案 0 :(得分:1)
以下声明:
from u in TblUsers
join c in TblCompanies on u.FkCompanyID equals c.PkCompanyID into g
from x in g.DefaultIfEmpty()
select u
会导致这个lambda表达式(根据优秀的应用程序LINQPad):
TblUsers
.GroupJoin (
TblCompanies,
u => u.FkCompanyID,
c => c.PkCompanyID,
(u, g) =>
new
{
u = u,
g = g
}
)
.SelectMany (
temp0 => temp0.g.DefaultIfEmpty (),
(temp0, x) => temp0.u
)