1
我不堅強的LINQ,但我想熟悉GroupJoin
需要解釋有關LINQ羣組加入語法
在下面的代碼,我想了解
var result = authors.GroupJoin(books,
author => author.AuthorId,
book => book.AuthorId,
(author, booksByAuthor) =>
new { Author = author.Name, Books = booksByAuthor });
這是從改寫這種加入到代碼
var result = from a in authors
join b in books on a.AuthorId equals b.AuthorId into booksByAuthor
select new { Author = a.Name, Books = booksByAuthor };
我通過在GroupJoin
語法混淆。我知道表格的作者和書籍一起,但接下來幾行的含義是什麼?
例如,author => author.AuthorId
,book => book.AuthorId
是什麼意思?這兩條線是否相當於
on a.AuthorId equals b.AuthorId
?
什麼是此行的意義:
(author, booksByAuthor) => new { Author = author.Name, Books = booksByAuthor }
我可以讀/理解加入到語句,但具有與該GroupJoin
一些困難。謝謝。
可能[重複](http://stackoverflow.com/a/15599143/861716)。 –