【发布时间】:2021-01-30 23:00:40
【问题描述】:
这是我第一次使用 GroupJoin。从我所看到的示例中,它的基本形式看起来非常简单,但是当我使用它时,我总是得到一个 NavigationExpandingExpressionVisitor 异常。这里举个例子:
[Table("Users")]
public class WAUser
{
public int Id { get; set; }
//TODO: Unique key
[NotNull]
public string UserUuid { get; set; }
[DefaultValue(true)]
public bool NotifyOnlineState { get; set; }
[DefaultValue(true)]
public bool NotifyOfflineState { get; set; }
}
public class WASubscription
{
public int Id { get; set; }
public string PackageIdentifier { get; set; } //Product package indentifier
public DateTime? ExpiresAt { get; set; } //When the subscription or trial expires
public bool Expired { get; set; }
public bool IsTrial { get; set; }
public int PhoneCount { get; set; } //Number of phones this subscriptions supplies
public int UserId { get; set; }
public WAUser User { get; set; }
}
var userSubscriptions = await dbContext.Users
.GroupJoin(dbContext.Subscriptions,
u => u.Id,
s => s.UserId,
(u, subscriptions) => new
{
User = u,
Subscriptions = subscriptions
})
.ToListAsync();
抛出的异常:
未处理的异常。 System.InvalidOperationException:处理 LINQ 表达式 'DbSet .GroupJoin( 外部:数据库集, 内部:u => u.Id, outerKeySelector: s => s.UserId, innerKeySelector: (u, 订阅) => new { 用户 = u, 订阅 = 订阅 })' 通过'NavigationExpandingExpressionVisitor' 失败。这可能表示 EF Core 中的错误或限制。看 https://go.microsoft.com/fwlink/?linkid=2101433了解更多详情 信息。
【问题讨论】:
标签: linq entity-framework-core