【发布时间】:2020-04-01 18:25:43
【问题描述】:
我有一个数据库模型,它有一个自己类型的父属性,如下所示:
public class MainModel
{
public int Id { get; set; }
public Entity Entity { get; set; };
}
public class Entity
{
public int Id { get; set; }
public int ParentId { get; set; }
public Entity Parent { get; set; }
}
现在我想获取与 MainModel 实例相关的所有实体的集合。 到目前为止,我已经尝试使用 SelectMany,创建一个新的实体数组,其中包含实体本身及其父级。但这会引发 InvalidOperationException
modelInstances.SelectMany(m => new []{ m.Entity, m.Entity.Parent });
例外:
System.InvalidOperationException
Processing of the LINQ expression 'm => new Entity[]
{
m.Entity,
m.Entity.Parent,
m.Entity.Parent.Parent
}' by 'NavigationExpandingExpressionVisitor' failed.
This may indicate either a bug or a limitation in EF Core. See https://go.microsoft.com/fwlink/?linkid=2101433 for more detailed information.
我有点困惑,因为在 EFCore Docs 中它说 SelectMany 受 LINQ-to-SQL 支持
有人知道我在这里可能缺少什么吗? 或者另一种获取实体及其父母的列表的方式。
【问题讨论】:
标签: c# linq-to-sql ef-core-3.0