c# - Linq Exception 表达式必须是 MemberExpression

标签 c# linq entity-framework-4 iqueryable

我正在处理一个 linq 查询,并尝试按照 Mutilevel include in C# Linq 中的建议将实体包含到多个级别.

所以我写下这样的查询

 query.Include(u => u.Stops.Select(d => d.Address).Select(c => c.City));

查询在哪里

IQueryable<SomeEntity> query

我得到了异常

The expression must be a MemberExpression

我的实体的屏幕截图是 enter image description here 请帮忙,谢谢

最佳答案

Include 的重载(扩展?)不支持通过方法链包含。但是,它确实支持包含表达式的嵌套:

query.Include(u => u.Stops.Select(d => d.Address.City));

// this would work too:
categories.Include(u => u.SubCategories.Select(c => c.Items.Select(i => i.Manufacturer)));
// equals
categories.Include("SubCategories.Items.Manufacturer");

Select 部分仅用于访问集合类型属性项的成员。

关于c# - Linq Exception 表达式必须是 MemberExpression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9094939/

相关文章:

c# - Linq to Entities 中的联合订单

c# - 带投影的 MongoDB 文本搜索

c# - 使用连接选择多个表中的多个项目

linq - 定制匹配最小起订量

.net - Entity Framework EDMX 复制到输出目录

c# - WCF - 已添加具有相同键的项目

c# - .NET 中的性能分析

c# - Linq to MySql 按日期分组

c# - 从三个非唯一的 List<T> 中获取一个唯一的 List<T>

entity-framework - Entity Framework 4 选择性延迟加载属性