asp.net - 为什么不能在 Include 内的 Where 方法中使用父实体的属性值?
问题描述
我需要查询子实体的创建日期与父实体相同的数据。所以,我尝试了以下代码:
context.Parent.Include(p => p.Child.Where(c => c.CreatedDate == p.CreatedDate)).ToList();
但它会引发无法翻译 LINQ 表达式的错误。我怎样才能实现这个功能或者有什么办法吗?
解决方案
你能做这样的事情吗:?
context.Parent.Include(p => p.Child.Where(c => c.CreatedDate == c.Parent.CreatedDate)).ToList();
从使用旧版本的 EF 开始,我假设您不知道Where 方法p
中的类型实例Parent
推荐阅读
- applescript - 为什么将文件夹放到 Applescript 应用程序上会显示一个对话框?
- c# - C#如何控制自定义类的序列化过程?
- php - 如何在 voyager 项目的编辑视图中包含选择输入?
- c# - 通过 HttpClient 使用 Google Cloud AutoML 时收到 401“未授权”错误
- xpath - 如何在 Xpath 中使用跟随来获取标签中的兄弟姐妹
- tensorflow - 了解COCO评估“最大检测数”
- python - 如何在 sklearn 中分别创建训练数据集和测试数据集?
- python - 如何使用python从多个文件夹中删除多个图像
- mysql - 如果下个月没有数据,则获取上个月的数据
- moodle - Moodle:是否可以仅从 javascript 访问用户