【发布时间】:2020-10-12 08:57:31
【问题描述】:
我有三个模型:
public class User
{
public long Id { get; set; }
public string Name { get; set; }
public ICollection<UserRole> UserRole { get; set; }
}
public class Role
{
public long Id { get; set; }
public long Title { get; set; }
public ICollection<UserRole> UserRole { get; set; }
}
public class UserRole
{
public long Id { get; set; }
public User user { get; set; }
public Role role { get; set; }
}
现在我有一种情况,我必须根据某个角色获取用户列表,基本上我必须根据 roleId 过滤用户。如何使用 ef core Linq 查询来实现这一点。
我尝试了以下查询,但它不能转换为 SQL。
context.User.Include(it => it.UserRole)
.ThenInclude(it => it.Role)
.Where(it => it.UserRole.Contains(new Role { Id = 1 }))
.ToListAsync();
【问题讨论】:
标签: c# .net entity-framework asp.net-core entity-framework-core