ToDictionary 的 EF Core 异常

EF Core exception with ToDictionary

我有一个抛出异常的简单 EF Core 查询,令我惊讶的是:

var test = await _context.GroupMessages
    .Select(m => new MinimalChannelMessage()
    {
        id = m.Id,
        er = m.Emojis.ToDictionary(e => e.Emoji, e => e.Users.Select(u => u.UserId))
    })
    .ToListAsync();

从查询中可以看出,表是GroupMessages -> Emojis -> N-to-M table with UserId

我得到的异常是:

When called from 'VisitLambda', rewriting a node of type 'System.Linq.Expressions.ParameterExpression' must return a non-null value of the same type. Alternatively, override 'VisitLambda' and change it to not visit children of this type.

我一直无法弄清楚为什么这个简单的查询会失败,或者异常消息试图告诉我什么。我很乐意提供任何帮助!

谢谢

虽然建议的错误报告 https://github.com/dotnet/efcore/issues/18440 可能相关,但我很难在列出的那些中找到替代方案。我试过了...

er = new Dictionary<string, string[]>(m.Emojis.AsEnumerable().Select(e => new KeyValuePair<string, string[]>(e.Emoji, e.Users.Select(u => u.UserId).ToArray())))

er = m.Emojis.AsEnumerable().ToDictionary(e => e.Emoji, e => e.Users.Select(u => u.UserId).ToArray())

None 这两个对我有用。所以我最终不得不只包含整棵树,然后在内存中执行 ToDictionary...