【发布时间】:2020-02-05 20:04:14
【问题描述】:
我有一个 user 表,其中包含一个名为 UserPriviliges 的嵌套表,我有一个 isDeleted 字段来识别已删除的数据而不实际删除它,我想使用 include 检索具有其权限的用户
public async Task<User> GetUser(Guid userId)
{
return await RepositoryContext.Users
.Include(x => x.UserPrivileges).ThenInclude(x => x.Privilege)
.FirstOrDefaultAsync(x => x.Id == userId);
}
如何过滤 UserPriviliges 以仅带入具有错误 isDeleted 属性的项目
在 EF Core
return await RepositoryContext.Users
.Include(x => x.UserPrivileges.Where(y=>y.IsDeleted)).ThenInclude(x => x.Privilege)
.FirstOrDefaultAsync(x => x.Id == userId);
但它在返回的 EF Core 3.1 中不再工作
Include 中使用的 Lambda 表达式无效
【问题讨论】:
标签: c# entity-framework asp.net-core asp.net-core-3.1 entity-framework-core-3.1