C# 无法为子集合翻译EF Core 3.0 Linq

C# 无法为子集合翻译EF Core 3.0 Linq,c#,linq,ef-core-3.0,C#,Linq,Ef Core 3.0,我知道从EF Core 2.2到EF Core 3.0的重大变化,但以下查询对我来说并不复杂,因为它是SQL中的一个简单连接 我有一个需要发送电子邮件的收件人列表。这些收件人是分组的,我可以将组列表添加到电子邮件通知中 这个查询有什么问题 var-emailAlert=new-emailAlert(); var emailRecipientMailboxes=\u emailRecipientRepository .Where(x=>x.GroupedRecipients.Any(erg=>em

我知道从EF Core 2.2到EF Core 3.0的重大变化,但以下查询对我来说并不复杂,因为它是SQL中的一个简单连接

我有一个需要发送电子邮件的收件人列表。这些收件人是分组的,我可以将组列表添加到电子邮件通知中

这个查询有什么问题

var-emailAlert=new-emailAlert();
var emailRecipientMailboxes=\u emailRecipientRepository
.Where(x=>x.GroupedRecipients.Any(erg=>emailAlert.RecipientGroups
.Any(aerg=>aerg.RecipientGroupId==erg.RecipientGroupId)))
.ToList()//已添加,以便EFCore在客户端上转换此内容
.选择(x=>新邮箱地址(x.FullName,x.Email))
.ToList();
以下是堆栈跟踪:

System.InvalidOperationException: The LINQ expression 'DbSet<GroupedRecipient>
    .Where(g => EF.Property<Nullable<Guid>>((EntityShaperExpression: 
        EntityType: Recipient
        ValueBufferExpression: 
            (ProjectionBindingExpression: EmptyProjectionMember)
        IsNullable: False
    ), "Id") != null && EF.Property<Nullable<Guid>>((EntityShaperExpression: 
        EntityType: Recipient
        ValueBufferExpression: 
            (ProjectionBindingExpression: EmptyProjectionMember)
        IsNullable: False
    ), "Id") == EF.Property<Nullable<Guid>>(g, "RecipientId"))
    .Any(g => __alert_RecipientGroups_0
        .Any(aerg => aerg.RecipientGroupId == g.RecipientGroupId))' 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(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
System.invalidoOperationException:LINQ表达式“DbSet”
.Where(g=>EF.Property((EntityShapeExpression:
EntityType:收件人
ValueBufferExpression:
(ProjectionBindingExpression:EmptyProjectionMember)
IsNullable:False
),“Id”)!=null&&EF.Property((EntityShapeExpression:
EntityType:收件人
ValueBufferExpression:
(ProjectionBindingExpression:EmptyProjectionMember)
IsNullable:False
),“Id”)==EF.Property(g,“RecipientId”))
.Any(g=>\u警报\u接收者组\u 0
.Any(aerg=>aerg.RecipientGroupId==g.RecipientGroupId))无法转换。以可以翻译的形式重写查询,或者通过插入对AsEnumerable()、AsAsAsAsyncEnumerable()、ToList()或ToListSync()的调用显式切换到客户端计算。看见https://go.microsoft.com/fwlink/?linkid=2101038 了解更多信息。

顺便说一句,有没有什么地方可以让我找到如何将查询转换为适用于EFCore 3.0的查询?可能是某种指南,概述了哪些类型的查询不起作用,以及如何修复它们的示例?

您能否提供确切的错误,以及上面添加的一些相关堆栈跟踪,谢谢:)您如何看待
emailAlert。当
emailAlert
是客户端变量时,RecipientGroups
将被转换为SQL?您传递了一个初始化对象,而LINQ无法将其转换为查询。你的问题是emailAlert。@奥利·塔兹:不,你必须用db的方式思考。想想LINQ不能翻译的东西,通常是有意义的,当然还有运行时错误:)。当然,您可以使查询像上面一样工作。如果您在发送查询之前添加了一个ToList(),那么所有对象都是对象,因此基本上您可以做任何您想做的事情,当然,它们都在内存中。