[英]Need help turning this LINQ expression into LINQ statement
I need help in turning this linq expression into a linq statment. 我需要帮助将此linq表达式转换为linq语句。 SampleData.Publishers and SampleData.Books are simple collections that I have from the Linq in Action book.
SampleData.Publishers和SampleData.Books是我在Linq in Action一书中提供的简单集合。
Here is the expression 这是表达式
var pubBooks =
from pub in SampleData.Publishers
join book in SampleData.Books on pub.Name equals book.Publisher.Name into pubbks
select new {
Publisher = pub.Name,
Books =
from b in pubbks
select b.Title
};
Here is what I have so far, but I can't seem to get the books collection defined in the anonymous type. 这是我到目前为止所做的,但我似乎无法获得匿名类型中定义的书籍集合。 Thanks for your time.
谢谢你的时间。
var pubBooks = SampleData.Publishers.Join(SampleData.Books, pub => pub.Name, book => book.Publisher.Name, (pub, book) => new {
Publisher=pub.Name,
Books=??????
});
You can use GroupJoin
. 您可以使用
GroupJoin
。
I didn't test this but it could look like this: 我没有测试这个,但它看起来像这样:
var pubBooks = SampleData.Publishers.GroupJoin(SampleData.Books, pub => pub.Name, book => book.Publisher.Name, (pub, bookColl) => new {
Publisher = pub.Name,
Books = bookColl.Select(b => b.Title)
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.