엔티티 프레임 워크를 사용하는 데있어 새로운 경험이 있습니다. 다 대다 관계를 사용하는 쿼리를 작성하는 방법을 고민하는 데 어려움을 겪고 있습니다. 3 개의 엔티티가 있습니다. 역할, 사용자 및 보안 성. 역할 여러 보안 개체에게을 가질 수 있으며, 보안 개체 많은 역할에 할당 할 수 있습니다. A 역할은 복수 사용자 및 사용자은 복수 역할을 가질 수 있습니다..many to many 관계를 포함하는 EF 쿼리를 작성하는 방법
내 질문 : 주어진 사용자 ID에 대한 Securable의 고유 목록을 제공하는 쿼리를 작성하려면 어떻게해야합니까?
여기 내 모델이 있는데, EF가 자동으로 나를위한 링크 테이블을 만듭니다.
public class SecurityContext : DbContext
{
public DbSet<User> Users { get; set; }
public DbSet<Role> Roles { get; set; }
public DbSet<Securable> Securables { get; set; }
}
public class User
{
public Guid UserId { get; set; }
public string Forename { get; set; }
public string Surname { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public virtual ICollection<Role> Roles { get; set; }
}
public class Securable
{
public Guid SecurableId { get; set; }
public string Name { get; set; }
public virtual ICollection<Role> Roles { get;set;}
}
public class Role
{
public Guid RoleId { get; set; }
public string Name { get; set; }
public virtual ICollection<Securable> Securables { get; set; }
public virtual ICollection<User> Users { get; set; }
}
이것은 승자처럼 보입니다. 내일 시험해 보겠습니다. –