2010-12-27 2 views
1

나는NHibernate에 JoinQueryOver과 게으른로드

var query = _session.QueryOver<TEntity>().JoinQueryOver<PropertyMultTable>(p => p.Properties).Where(propertyPredicate).List(); 

이 쿼리는 다음 SQL

select this_.BaseEntity_id as BaseId0_1_ , 
     this_1_.Label as Label0_1_ , 
     this_1_.Description as Descript3_0_1_ , 
     this_1_.CreatedDate as CreatedD4_0_1_ , 
     this_.Width as Width2_1_ , 
     this_.Height as Height2_1_ , 
     this_.Duration as Duration2_1_ , 
     propertymu1_.id as id4_0_ , 
     propertymu1_.Name as Name4_0_ , 
     propertymu1_1_.DateTimeValue as DateTime2_5_0_ , 
     propertymu1_2_.IntegerValue as IntegerV2_6_0_ , 
     propertymu1_3_.DecimalValue as DecimalV2_7_0_ , 
     propertymu1_4_.StringValue as StringVa2_8_0_ 
from [Video] this_ 
     inner join [BaseEntity] this_1_ on this_.BaseEntity_id = this_1_.BaseId 
     inner join [PropertyMultTable] propertymu1_ on this_.BaseEntity_id = propertymu1_.BaseEntity_id 
     left outer join DateTimeValues propertymu1_1_ on propertymu1_.id = propertymu1_1_.PropertyMultTable_id 
     left outer join IntegerValues propertymu1_2_ on propertymu1_.id = propertymu1_2_.PropertyMultTable_id 
     left outer join DecimalValues propertymu1_3_ on propertymu1_.id = propertymu1_3_.PropertyMultTable_id 
     left outer join StringValues propertymu1_4_ on propertymu1_.id = propertymu1_4_.PropertyMultTable_id 
where (propertymu1_2_.IntegerValue >= 459144 
      and propertymu1_2_.IntegerValue <= 691982 
     ) 

를 생성하는 쿼리를해야하지만 등록하지 않고, 단지 엔터티 싶어.

select this_.BaseEntity_id as BaseId0_1_ , 
     this_1_.Label as Label0_1_ , 
     this_1_.Description as Descript3_0_1_ , 
     this_1_.CreatedDate as CreatedD4_0_1_ , 
     this_.Width as Width2_1_ , 
     this_.Height as Height2_1_ , 
     this_.Duration as Duration2_1_ 
from [Video] this_ 
     inner join [BaseEntity] this_1_ on this_.BaseEntity_id = this_1_.BaseId 
     inner join [PropertyMultTable] propertymu1_ on this_.BaseEntity_id = propertymu1_.BaseEntity_id 
     left outer join DateTimeValues propertymu1_1_ on propertymu1_.id = propertymu1_1_.PropertyMultTable_id 
     left outer join IntegerValues propertymu1_2_ on propertymu1_.id = propertymu1_2_.PropertyMultTable_id 
     left outer join DecimalValues propertymu1_3_ on propertymu1_.id = propertymu1_3_.PropertyMultTable_id 
     left outer join StringValues propertymu1_4_ on propertymu1_.id = propertymu1_4_.PropertyMultTable_id 
where (propertymu1_2_.IntegerValue >= 459144 
      and propertymu1_2_.IntegerValue <= 691982 
     ) 

하거나, 심지어 더 나은,이 같은 :

select distinct this_.BaseEntity_id as BaseId0_1_ , 
     this_1_.Label as Label0_1_ , 
     this_1_.Description as Descript3_0_1_ , 
     this_1_.CreatedDate as CreatedD4_0_1_ , 
     this_.Width as Width2_1_ , 
     this_.Height as Height2_1_ , 
     this_.Duration as Duration2_1_ 
from [Video] this_ 
     inner join [BaseEntity] this_1_ on this_.BaseEntity_id = this_1_.BaseId 
     inner join [PropertyMultTable] propertymu1_ on this_.BaseEntity_id = propertymu1_.BaseEntity_id 
     left outer join IntegerValues propertymu1_2_ on propertymu1_.id = propertymu1_2_.PropertyMultTable_id 
where (propertymu1_2_.IntegerValue >= 459144 
      and propertymu1_2_.IntegerValue <= 691982 
     ) 

내가 유창함 NHibernate에이 작업을 수행 할 수 있습니다,이 같은 SQL이 필요하십니까? 답변 주셔서 감사합니다.

+0

당신이 비디오의 클래스 선언을 추가 할 수 있습니까? – Baz1nga

+0

비디오는 Width, Height 및 Duration의 3 가지 속성을 가진 클래스이며 Id, Label, Description 및 CreatedDate 속성 만 포함하는 BaseEntity에서 파생됩니다. – msi

+0

Fluent NHibernate는 쿼리를 만들지 않고 매핑을 만드는 데 사용됩니다 . –

답변

0

여기 HQL을 사용하여 어떻게 할 수 있습니다.

var hqlQuery=string.Format("select v from Video as v inner join v.BaseEntity 
as be inner join v.PropertyMultTable as pmt left outer join pmt.IntegerValues 
as iv where be.BaseEntity_id=v.BaseId and be.BaseEntity_id=pmt.BaseEntity_id and 
pmt.Id=iv.PropertyMultTable_id and iv.IntegerValue >={0} and iv.IntegerValue 
<={1}", 459144,691982); 

내부 결합이 완료되면 여기에 유의하십시오. 속성 이름이 위의 쿼리에서 언급 한 것과 동일하다고 가정합니다. 그들은 당신의 재산을 언급하는 것과 똑같은 것이어야합니다. 그렇지 않으면 당신은 nhibernate 예외를 얻을 것입니다.

만약 작동하지 않는다면 전체 클래스 다이어그램을 게시하십시오. 다음과 같이

이 쿼리를 실행할 수 있습니다

session.CreateQuery(hqlquery).List<Video>(); 
+0

이것은 내 목표를위한 해결책이 아닙니다. 제네릭 저장소가 있기 때문에 HQL이 필요하지 않습니다. 이미지 나 문서 같은 다른 클래스를 TEntity로 사용할 수 있습니다. – msi

+0

그러면 Criteria 쿼리를 고려해야합니다. 당신이 나에게 수업 다이어그램을 제공하면 당신을 도울 수 있습니다. – Baz1nga

0

아마 Future()를 사용하여 :

var query = 
    _session.QueryOver<TEntity>() 
    .JoinQueryOver<PropertyMultTable>(p => p.Properties) 
    .Future() 
    .Where(propertyPredicate).List();