NHibernate ICriteria with a bag

Posted by plunk on Stack Overflow See other posts from Stack Overflow or by plunk
Published on 2009-02-13T19:32:48Z Indexed on 2010/04/03 7:53 UTC
Read the original article Hit count: 465

Filed under:
|

Hi,

Just a quick question. If I've got 2 tables that are joined in a 3rd table with a many-to-many relationship, is it possible to write an ICriteria with expressions in one of the tables and the join table?

Lets say the mapping file looks something like:

    <bag name ="Bag" table="JoinTable" cascade ="none">
      <key column="Data_ID"/>
      <many-to-many class="Data2" column="Data2_ID"/>
    </bag>

Is it then possible to write an ICriteria like the following?

        ICriteria crit = session.CreateCriteria(typeof(Data));
        crit.Add(Expression.Eq("Name", name));
        crit.Add(Expression.Between("Date", startDate, endDate));
        crit.Add(Expression.Eq("Bag", data2IDNumber));

When I try this, it tells me I the expected type is IList, whereas the actual type is Bag.

Thanks.

© Stack Overflow or respective owner

Related posts about c#

Related posts about nhibernate