2013-07-04 4 views
-2
NHibernate에

사용하여 두 개의 테이블을 결합. 거대한 양의 제품 유형이 있습니다.내가 두 개의 테이블이

+0

으로 ORMs가 사용되는 관련 객체를 검색하기 위해 섭니다. nhibernate.cfg에서 관계를 지정하면 관련 객체는 부모를 물어볼 때 자동으로로드됩니다. –

답변

0

우리는 NHibernate에서 테이블이 아닌 객체 모델에 대해 쿼리를 작성합니다. 당신이 당신의 객체 모델을 설명하지 않기 때문에, 나는 당신의 테이블이 어떻게 보이는지에 근거하여 뻔뻔스럽게 가정했다. 다음과 같이 될 것이다 NHibernate에 Linq에를 사용하여

한 가지 가능한 쿼리 : 당신이 할 필요가 없습니다

// Notice no ToList(), since we want it as a subquery. 
var usedProductTypesIdSubquery = 
    session.Query<Product> 
      .Select(product => product.ProductType.Id); 

var usedProductTypes = 
    session.Query<ProductType> 
      .Where(productType => usedProductTypesIdSubquery.Contains(productType.Id) 
      .ToList(); 

// Because we are using a subquery, and contains (the 'IN' clause in SQL), the 
// resulting list usedProductTypes will not contain duplicates.