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

标签 c# 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)
  };

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

相关文章:

c# - 填补emgu cv中的漏洞

c# - 如何使用 Linq 查找 Min() 并将 Min 元素设置为 0

c# - 迁移到 dbcontext LINQ where 子句字符串参数

c# - 将 JSON 数组绑定(bind)到 ASP.NET MVC 3 中的列表的问题模型

c# - CoreCLR 中的 Type.GetCustomAttributes 方法在哪里?

c# - 将 linq 查询连接到 View 模型的结果

c# - 拆分逗号分隔的字符串并比较列表中的每个值

c# - LINQ 不同查询

c# - 如何在 C# 中关闭特定的 Windows 资源管理器窗口?

c# - 如何反序列化已更改类型的旧数据?