将具有多个froms的linq查询表达式转换为扩展方法语法

我将此代码转换为扩展方法语法时遇到问题:

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) }; 

试试这个:

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