本文介绍了与多个转换LINQ查询表达式320交织成扩展方法的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有麻烦的代码转换为扩展方法的语法:
VAR的查询=从C在_context.Customers $ B从o在c.Orders
$ b,其中o.DateSent == NULL
选择新CustomerSummary
{
n = c.Id,
=用户名c.Username ,
OutstandingOrderCount = c.Orders.Count
};
任何想法?
解决方案
VAR的查询= _context.Customer
。凡(C => c.Orders.Any(O = GT; o.DateSent == NULL) )
。选择(C =>新建CustomerSummary
{
n = c.Id,
=用户名c.Username,
OutstandingOrderCount = c.Orders.Count (O => o.DateSent == NULL)
};
I am having trouble converting this code into extension method syntax:
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
};
Any ideas?
解决方案
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)
};
这篇关于与多个转换LINQ查询表达式320交织成扩展方法的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!