我无法将此代码转换为扩展方法语法:
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
};
有什么想法吗?
答案 0 :(得分:2)
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)
};
答案 1 :(得分:1)
试试这个:
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
});