C# .NET Core 3.1与PostreSQL jsonb JsonDocument映射不起作用,因为;无法翻译LINQ表达式;
我尝试了以下关于通过动态映射访问json DOM的内容。本教程建议使用C# .NET Core 3.1与PostreSQL jsonb JsonDocument映射不起作用,因为;无法翻译LINQ表达式;,c#,json,postgresql,.net-core,entity-framework-core,C#,Json,Postgresql,.net Core,Entity Framework Core,我尝试了以下关于通过动态映射访问json DOM的内容。本教程建议使用JsonDocument,然后在其上使用.GetProperty(string),但似乎只能通过.RootElement访问它(这是一个JsonElement,它确实包含GetProperty方法) 无论哪种方式,我都会遇到以下例外情况: System.InvalidOperationException: The LINQ expression 'DbSet<GameEntity> .Where(g => g
JsonDocument
,然后在其上使用.GetProperty(string)
,但似乎只能通过.RootElement
访问它(这是一个JsonElement
,它确实包含GetProperty
方法)
无论哪种方式,我都会遇到以下例外情况:
System.InvalidOperationException: The LINQ expression 'DbSet<GameEntity>
.Where(g => g.GameInfo.GetProperty("ReadableIdentifier").ToString() == __readableIdentifier_0)'
could not be translated.
Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly
by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync().
有什么我遗漏的吗?这应该标记为C#和EF Core,而不是其他任何东西!这个问题在EF核心文档中得到了很好的解释:嘿@CoolBots,感谢您的回复。我可以向您询问来源吗?我编辑了我的初始评论,将链接添加到文档中。基本上,LINQ查询必须可翻译为SQL(客户端评估)。您需要重新编写查询。我链接的页面也有示例-请查看该文档的“不受支持的客户端评估”部分。我很抱歉,但我觉得您跳过了我发送的链接。Npgsql引用在他们的文档中声明了一些非常类似的东西作为示例,那么我的查询真的有那么糟糕吗?我认为是
GetProperty
调用导致了错误;我现在没有时间深入研究,但我确实错过了这个环节;我删除了我的否决票,因为我知道你其余标签的理由是基于什么。
var gameEntity = _context.Games
.Include(x => x.Characters)
//.AsEnumerable()
.Where(x => x.GameInfo.GetProperty("ReadableIdentifier").ToString() == readableIdentifier)
.FirstOrDefault();