Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
I am using nHibernate 1.2.0 and i am trying to query a bunch of objects that have child objects.
Mapping documents:
Say I have a class Bid which contains a unidirectional many to one relationship with another class Item.
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Test.ClientManagement.Model.Bid, Test.ClientManagement.Model" table="bid" lazy="false">
<cache usage="read-write"/>
<id name="Id" column="bid_id">
<generator class="increment" />
</id>
<property name="StartTime" column="start_ts" not-null="true"/>
<property name="BidDescription" column="bid_ds" not-null="true"/>
<many-to-one name="Item" column="item_id" class="Test.ClientManagement.Model.Item, Test.ClientManagement.Model"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
(here T is the type Bid)
ICriteria criteria = Session.Current.CreateCriteria(typeof(T))
.Add(Expression.Between("StartTime", new DateTime(2006, 1, 1, 9, 0, 0), new DateTime(2006, 1, 1, 21, 0, 0)));
criteria.SetCacheable(true);
criteria.SetTimeout(60);
return criteria.List();
Now this currently works fine but I want to add to the criteria that the Item name has to be like a certain string.
How do I add to this criteria to also match certain Item properties.
I tried adding an
.Add(Expression.Like("Item.Name", "Test%"));
to the code but this errors with:
"Additional information: could not resolve property: Item.ItemName of: Test.ClientManagement.Model.Bid"
Any help would be much appreciated.