Hello all,
I am using NH to load up ILists (Bags) with items.
I was hoping to make one call on a session to have everything load in a single database trip and then query the session object to return individual items (without making another db call).
I can't seem to get this to happen.
The code I'm using to load 'everything' is
Code:
IList result = Session.CreateCriteria(typeof(clsItem)).List();
I am then calling the following for individual items
Code:
IList i = this.DataBinder.Session.Find("from clsItem i where i.Litm = '" + Litm + "'");
Note - the Session object is the same and it hasn't been closed or disconnected.
If it helps, here is the map for clsItem...
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="OPWLibrary.clsItem, OPWLibrary" table="tblItems">
<id name="Litm" column="cLITM" unsaved-value="0" length="6" type="string">
<generator class="assigned" />
</id>
<property name="Description" column="cDescription"/>
<property name="ShelfLifeDays" column="iShelfLifeDays"/>
<bag name="OrdersNH" inverse="true" lazy="true">
<key column="cLITM"/>
<one-to-many class="OPWLibrary.clsOrder,OPWLibrary"/>
</bag>
</class>
</hibernate-mapping>
Ideally, I guess that I would want to use a MAP/IDictionary to achieve this, however the collection has to participate in a bi-directional relationship, so (as I understand it) I'm restricted to bags and maps.
I'd be very appreciative if someone could give me some advice on how to tackle this issue. I've thought of putting a function in my collection wrapper that loops through the IList and returns a result... Or maybe even populate it into a Hashtable on construction... Are these the best ways to tackle this, or, Is there a way to return the object from the NH Session?
Thanks very much in advance,
Damien Sawyer