문제

데이터 액세스에 nhibernate를 사용하려고 노력하고 있으며 다음과 같이 보이는 2 개의 간단한 엔티티가 있습니다.

public class User : IEntity
{
   public int ID { get; set; }
   public string FirstName { get; set; }
   public string LastName { get; set; }
   public string Email { get; set; }
   public string Logon { get; set; }
   public string Password { get; set; }
   public ICollection<Role> Roles { get; set; }

   public bool IsNew
   {
      get { return (ID == 0) ? true : false; }
   }

   public User()
   {
      Roles = new List<Role>();
   }
}

public class Role : IEntity
{
   public int ID { get; set; }
   public string RoleName { get; set; }
   public string RoleDescription { get; set; }

   public bool IsNew
   {
      get { return (ID == 0) ? true : false; }
   }
}

내 질문 ...... 역할 컬렉션에서 ID 1의 역할을 포함하는 사용자를 찾으려면 어떻게 기준을 구성합니까?

도움이 되었습니까?

해결책

신경 쓰지 마세요. 이것은 결국 비교적 직설적이었습니다.

// role was the role passed in to my Find method.
var criteria = DetachedCriteria.For(typeof (User))
            .CreateCriteria("Roles")
            .Add(Restrictions.Eq("ID", role.ID));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top