【发布时间】:2020-12-08 14:41:33
【问题描述】:
我有一个简单的父/子结构,它存储发送给用户的消息的历史记录。我已经生成了一个 dbContext 并链接了所有实体(使用 EF Core Power Tools)。
那么当 UserID 位于子表(称为 PushNotificationReceipients)中时,我如何才能真正获取某个 UserID 的所有通知?
我以为我可以做这样的事情,但它失败并出现错误:
var recipient = new PushNotificationRecipient();
recipient.UserId = userId;
var results = _dbContext.PushNotifications
.Include(t => t.PushNotificationContents)
.Where(t => t.PushNotificationRecipients.Contains(recipient))
.ToList();
..但这给出了错误
无法翻译 LINQ 表达式。要么以可翻译的形式重写查询,要么通过插入对 AsEnumerable() 的调用显式切换到客户端评估
..而且客户评估太慢了。
有什么办法可以在 Linq 中做到这一点,还是我需要直接传入 SQL?
【问题讨论】:
标签: c# entity-framework-core linq-to-entities