항목이 있습니다. 각 항목은 그룹에 속합니다. 그리고 각 항목은 텍스트 검색을 높이는 데 유용한 태그 (문자열) 목록을 소유합니다 (비어있을 수도 있음). 검색은 설명과 일치하는 항목, 해당 항목이 속한 그룹의 설명 또는 하나 이상의 태그 (모두 OR 조건)를 찾습니다.문자열 컬렉션에서 QueryOver 필터링 : NullReferenceException
다음 QueryOver를 통해 검색 키를 사용하여 항목을 선택하려고합니다.
<class name="Item" table="Items">
<id name="Id">
<generator class="guid.comb" />
</id>
<natural-id>
<property name="Code" not-null="true" />
</natural-id>
<property name="Description" not-null="true" />
<many-to-one name="Group" column="ID_Group" not-null="true" fetch="join" />
<property name="ExpiryDate" />
<list name="Tags" table="Items_Tags">
<key column="ID_Item" />
<index column="Idx" />
<element column="Tag" />
</list>
</class>
쿼리 실행이 NullReferenceException이 예외 : 다음과 같이
Item i = null;
ItemGroup g = null;
String tag = null;
session
.QueryOver<Item>(() => i)
.JoinAlias(x => x.Group,() => g, JoinType.InnerJoin)
.JoinAlias(x => x.Tags,() => tag, JoinType.LeftOuterJoin) //left outher join because it is possible for an item to have no tags at all.
.Where(
new Disjunction()
.Add(Restrictions.On(() => p.Description).IsInsensitiveLike(searchKey, MatchMode.Anywhere))
.Add(Restrictions.On(() => g.Description).IsInsensitiveLike(searchKey, MatchMode.Start))
.Add(Restrictions.On(() => tag).IsInsensitiveLike(searchKey, MatchMode.Start)) //this condition throws an exception
)
.Take(maxResults)
.Future();
항목 클래스는 매핑됩니다. 분리에서 마지막 조건을 제거하면 예외가 발생하지 않습니다.
나는 마법의 문자열을 사용하지 않고 이것을 제거하지 못했습니다.
.Add (Restrictions.On (() => 태그) .IsInsensitiveLike (searchKey, MatchMode.Start))이 줄에 태그 태그로 태그 테이블의 별칭을 정의했기 때문에 태그를 사용해야합니다. 검색에 언급 된 필드가 없습니다. – Deepesh
태그는 일반 String 객체입니다. 태그 속성이 없습니다. – Marcello