EF核心:必须是可还原节点

JDS*_*JDS 2 entity-framework entity-framework-core .net-core

我不确定为什么会收到错误消息:“必须是可还原节点”

这是我的查询。我正在使用EF Core 2.2运行Core 2(因此我应该拥有以前版本中的修复程序)

    IQueryable<Gizmo> gizmos = _context.Gizmo;


    IQueryable<GizmoViewModel> dataReferences = (
        gizmos.SelectMany(j => j.DataReferences.Select(r =>
            new GizmoViewModel()
            {
                GizmoId = j.Id,
                DataId = r.DataId
            }
        ))
    );
Run Code Online (Sandbox Code Playgroud)

Iva*_*oev 5

简单(令人遗憾)您遇到的是当前EF Core查询翻译错误之一。

看起来是由于访问SelectMany内部Select表达式中的外部lambda参数引起的。

解决方法是使用另一个SelectMany重载,该重载具有第二个具有外部和内部参数的lambda(我想这是C#编译器在转换LINQ查询语法时使用的):

IQueryable<GizmoViewModel> dataReferences = (
    gizmos.SelectMany(j => j.DataReferences, (j, r) =>
        new GizmoViewModel()
        {
            GizmoId = j.Id,
            DataId = r.DataId
        }
    )
);
Run Code Online (Sandbox Code Playgroud)