2014-06-09 1 views
0

이 SQL 쿼리를 Nhibernate로 가져 오는 방법은 무엇입니까? 당신이 LINQ 잘 알고있는 경우는 매우 매우 간단Nhibernate에 대한 SQL 쿼리 만들기

SELECT Customer.name 
FROM Company INNER JOIN Customer ON Company.CompanyId = Customer.CompanyId 
where CompanyId = 2 

답변

0

,
직접 엔티티로 바로 신청 기준에 액세스 할 수 있습니다. 그 엔티티의 속성을 얻을 것이므로 n 번째 노드까지 액세스 할 수 있습니다.

NHibernate에 엔티티로 참조 필드의 관리 ..

 //Here is the sample this may work 
     //CustomerList is a nhibernate entity list. 
     //CompanyId is also an entity which is a reference to the CompanyId of Company table. 
     // you will get the list of customers based on condition. 
     var CustomerList = new List<Customer>(); 
     var custList = from cust in CustomerList where cust.CompanyId.CompanyId == 2 select cust; 
+0

LINQ – user3635120

+0

@ user3635120에 익숙하지 않은데 데이터베이스 액세스를위한 linq 팬이 아니지만 언어의 중요한 부분입니다. 약간의 독서를 제안합니다. – Liath

0

당신은 당신이 ICriterion 사용할 수있는 ID (2)와 함께 회사를 대표하는 기업이있어 가정 취합니다

return this.GetSession().CreateCriteria<Customer>() 
    .Add(Restrictions.Eq("Company", company)) 
    .List<Customer>(); 

이렇게하면 회사와 관련된 고객 목록이 반환됩니다 (Customer 클래스의 속성을 "회사"라고 가정).

는 이름 만 할 얻으려면 : 당신은 모든 고객이 하나 개의 DB를 히트보다는 느리게 그들에게 한 번에 하나씩로드에서로드됩니다 알고

customers.Select(c => c.name); 

나는이 방법을 건의 할 것입니다.