我想实现两件事。
首先,我希望此连接不区分大小写。
我以前使用过这种不区分大小写的 where 子句
where b.foo.Equals(foo, StringComparison.OrdinalIgnoreCase)
但我现在不知道如何在 join 中使用它。
其次,我想返回包含作者姓名和书籍数量的元组。
var query = from b in Books
join a in authors on b.Author equals a
select Tuple.Create(a, _count_of_authors_books_);
return query;
谢谢。
最佳答案
Linq 确实支持使用不区分大小写的匹配进行连接,但只是在查询语法中不支持。您需要使用 Method Syntax .
var query = Books.Join(
authors, // the other list
book => book.Author, // what to compare in "Books"
author => author, // what to compare in "authors"
(book, author) => Tuple.Create(author, _count_of_authors_books_), // what to select at the end
StringComparer.InvariantCultureIgnoreCase); // how to do the comparison
StringComparer
有一些其他变体,请使用您需要的变体。
关于c# - Linq 不区分大小写的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29612122/