我有一个使用lambda语法的LINQ查询:
var query =
books
.Where(book => book.Length > 10)
.OrderBy(book => book.Length)
我想创建一个匿名类型来存储投影,类似于:
var query = from book in books
where book.Length > 10
orderby book
select new { Book = book.ToUpper() };
如何在lambda语法中“选择新”?
谢谢,
斯科特
答案 0 :(得分:42)
像这样:
var query =
books
.Where(book => book.Length > 10)
.OrderBy(book => book.Length)
.Select(book => new { Book = book.ToUpper() });