1.0.2
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="WTECBSC.VO.ItemDetails,WTECBSC" table="ITEM_DETAILS">
<composite-id name="ID" class="WTECBSC.VO.ItemDetailsCompositeID,WTECBSC">
<key-many-to-one name="ItemId" column="item_id" class="WTECBSC.VO.Item,WTECBSC" />
<key-property column="language_code" type="String" name="LanguageCode" />
</composite-id>
<property column="NAME" type="String" name="Name" not-null="true" length="50" />
<property column="MODEL" type="String" name="Model" not-null="true" length="50" />
<property column="DESCRIPTION" type="String" name="Description" not-null="true" length="7200" />
<property column="MAIN_FEATURES" type="String" name="MainFeatures" not-null="true" length="7200" />
<property column="SPECIFICATIONS" type="String" name="Specifications" not-null="true" length="7200" />
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="WTECBSC.VO.Item,WTECBSC" table="ITEM">
<id name="ItemId" column="ITEM_ID" type="Decimal" unsaved-value="0">
<generator class="native"/>
</id>
<bag name="ClientCoreList" inverse="true" lazy="true" >
<key column="ITEM_ID" />
<one-to-many class="WTECBSC.VO.ClientCore,WTECBSC" />
</bag>
<bag name="ItemDetailsList" inverse="true" lazy="true"
access="NHibernate.Generics.GenericAccessor, NHibernate.Generics">
<key column="item_id" />
<one-to-many class="WTECBSC.VO.ItemDetails,WTECBSC" />
</bag>
<bag name="ItemPriceLevelList" inverse="true" lazy="true"
access="NHibernate.Generics.GenericAccessor, NHibernate.Generics">
<key column="item_id" />
<one-to-many class="WTECBSC.VO.ItemPriceLevel,WTECBSC" />
</bag>
<bag name="ItemProfileList" inverse="true" lazy="true" >
<key column="ITEM_ID" />
<one-to-many class="WTECBSC.VO.ItemProfile,WTECBSC" />
</bag>
<bag name="PurchaseOrderTransactionList" inverse="true" lazy="true" >
<key column="ITEM_ID" />
<one-to-many class="WTECBSC.VO.PurchaseOrderTransaction,WTECBSC" />
</bag>
<bag name="TransactionList" inverse="true" lazy="true" >
<key column="ITEM_ID" />
<one-to-many class="WTECBSC.VO.Transaction,WTECBSC" />
</bag>
<bag name="TransactionSavedList" inverse="true" lazy="true" >
<key column="ITEM_ID" />
<one-to-many class="WTECBSC.VO.TransactionSaved,WTECBSC" />
</bag>
<many-to-one name="SupplierId" column="SUPPLIER_ID" class="WTECBSC.VO.Supplier,WTECBSC" />
<many-to-one name="CategoryId" column="CATEGORY_ID" class="WTECBSC.VO.Categories,WTECBSC" />
<property column="SKU" type="String" name="Sku" not-null="true" length="50" />
<property column="LOGO" type="String" name="Logo" length="255" />
<property column="STATUS" type="Boolean" name="Status" not-null="true" />
<property column="PRICE" type="Decimal" name="Price" not-null="true" />
<property column="INVENTORY" type="Decimal" name="Inventory" not-null="true" />
<property column="SHIPPING_CHARGE" type="Decimal" name="ShippingCharge" not-null="true" />
<property column="CREATION_DATE" type="DateTime" name="CreationDate" not-null="true" />
<property column="MODIFY_DATE" type="DateTime" name="ModifyDate" not-null="true" />
</class>
</hibernate-mapping>
ItemDetails has attributes of an item. So what I want to do is search on say the features column. I want it to return all the items that have that features value....The problem is that when I profile the SQL what it does is that it does the search inside the ItemDetails table. And than it runs a different SQL query to instantiate each individual item. So if the first search returns 300 items than 300 queries are run after that to fill all the item objects.
Code:
ICriteria criteria = NSession.CreateCriteria(typeof(Item)).CreateAlias("ItemDetailsList", "dtls")
.Add(Expression.Like("dtls.MainFeatures", lstKeywords[0], MatchMode.Anywhere));
ICriteria criteria = NSession.CreateCriteria(typeof(ItemDetails)).Add(Expression.Like("MainFeatures", lstKeywords[0], MatchMode.Anywhere));
Both of those cause that exact same thing to happen....The only way I can think of to remedy this. Is to instead of making the Item field in itemdetails a
<key-many-to-one name="ItemId" column="item_id" class="WTECBSC.VO.Item,WTECBSC" />
is to make it a property instead. That way it returns a list of decimals and than I can do a criteria get on all the ids for the item table (which only takes one call)
what I would RATHER have it do. Is create a SINGLE sql query based on my search paramters in the itemdetails object and from that be able to build all the returned items.