转换为扩展方法语法

转换为扩展方法语法

This question already has answers here:
Nested “from” LINQ query expressed with extension methods

(3 个回答)


5年前关闭。




我无法将此代码转换为扩展方法语法:
var query = from c in _context.Customers
                        from o in c.Orders
                        where o.DateSent == null
                        select new CustomerSummary
                        {
                            Id = c.Id,
                            Username = c.Username,
                            OutstandingOrderCount = c.Orders.Count
                        };

有任何想法吗?

最佳答案

var query = _context.Customer
  .Where(c => c.Orders.Any(o => o.DateSent == null))
  .Select(c => new CustomerSummary
  {
    Id = c.Id,
    Username = c.Username,
    OutstandingOrderCount = c.Orders.Count(o => o.DateSent == null)
  };

关于c# - 将具有多个 from 的 linq 查询表达式转换为扩展方法语法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6281793/

10-09 07:27