我有以下加入:
var simpleJoin = from b in books
join p in publishers on b.PublisherName equals p.Name
where p.Id == 1
select b;
使用方法语法的等效项是什么?我被过滤器绊倒了:
simpleJoin = books.Join(publishers, p => p.PublisherName, b => b.Name, (b, p) => b).Where(*can't access publishers here*)
我可以不使用书籍
作为我的源收藏吗?我想知道如果我们有多个连接,我们如何管理过滤。
最佳答案
您需要在 resultSelector
中包含 b 和 p。例如,使用匿名类型的对象:
simpleJoin = books.Join(publishers, p => p.PublisherName, b => b.Name,
(b, p) => new { b = b, p = p })
.Where(result => result.p.Id == 1)
.Select(result => result.b);
关于c# - 从 LINQ 查询语法转换为方法语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21419931/