Hi there, I have a collection of comments that I wish to filter. The collection has Parent and Children objects of the same type (ie. it is a hierarchy of objects).
I have tried to filter the collection as follows:
Code:
return (ArrayList)Repository.Instance.ActiveSession.Filter(this.AuctionComments, "WHERE Count(this.Parents) = 0");
but this generates the following error:
Code:
NHibernate.QueryException: unindexed collection before [] [WHERE Count(this.Parents) = 0] at NHibernate.Hql.PathExpressionParser.PrepareForIndex(QueryTranslator q) at NHibernate.Hql.PathExpressionParser.End(QueryTranslator q) at NHibernate.Hql.WhereParser.DoPathExpression(String token, QueryTranslator q) at NHibernate.Hql.WhereParser.DoToken(String token, QueryTranslator q) at NHibernate.Hql.WhereParser.Token(String token, QueryTranslator q) at NHibernate.Hql.ClauseParser.Token(String token, QueryTranslator q) at NHibernate.Hql.PreprocessingParser.Token(String token, QueryTranslator q) at NHibernate.Hql.ParserHelper.Parse(IParser p, String text, String seperators, QueryTranslator q) at NHibernate.Hql.QueryTranslator.Compile() at NHibernate.Hql.QueryTranslator.Compile(ISessionFactoryImplementor factory, IDictionary replacements, Boolean scalar) at NHibernate.Hql.FilterTranslator.Compile(String collectionRole, ISessionFactoryImplementor factory, IDictionary replacements, Boolean scalar) at NHibernate.Impl.SessionFactoryImpl.GetFilter(String filterString, String collectionRole, Boolean scalar) at NHibernate.Impl.SessionImpl.GetFilterTranslator(Object collection, String filter, QueryParameters parameters, Boolean scalar) at NHibernate.Impl.SessionImpl.Filter(Object collection, String filter, QueryParameters parameters) at NHibernate.Impl.SessionImpl.Filter(Object collection, String filter)
Can anyone tell me if it is possible to filter a collection in this way, and a suitable where clause if so?
AHA, Ben :)
Hibernate version: 1.0.2.0
Mapping documents:Code:
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="SoleBidder.Domain.Classes" assembly="SoleBidder.Domain" default-access="field.camelcase">
<class name="AuctionComment" table="`AuctionComment`">
<jcs-cache usage="read-write" />
<id name="Id" column="AuctionCommentId" type="Int32" unsaved-value="0">
<generator class="identity" />
</id>
<bag name="Parents" table="AuctionCommentHierarchy" inverse="true" lazy="true" order-by="ParentAuctionCommentId" cascade="none">
<key column="AuctionCommentId" />
<many-to-many class="AuctionComment" column="ParentAuctionCommentId" />
</bag>
<bag name="Children" table="AuctionCommentHierarchy" lazy="true" order-by="AuctionCommentId" cascade="none">
<key column="ParentAuctionCommentId" />
<many-to-many class="AuctionComment" column="AuctionCommentId" />
</bag>
<property name="Name" column="Name" type="String" not-null="true" />
<property name="Subject" column="Subject" type="String" not-null="false" />
<property name="Message" column="Message" type="String" not-null="false" />
<property name="PostDate" column="PostDate" type="DateTime" not-null="true" />
<many-to-one name="Auction" column="AuctionId" class="Auction" not-null="true"/>
</class>
</hibernate-mapping>
Name and version of the database you are using:SQL Server 2000
[/code]