Suppose I have a many-to-one relationship and a Ilist of child objects implemented in my class definition and I use a stored procedure to get all the objects of this class using the IQuery object's List method. Will Nhibernate still load the relationships also for me or is it not possible at this moment.
I am getting an error which says. IndexOutOfRangeException: Last4_5_0_]
I am attaching a copy of the hbm file for future references.
Code:
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="BusinessObjects"
assembly="BusinessObjects">
<!-- Mappings for class 'Product' -->
<class name="Product" table="dbo.Products" lazy="true">
<!-- Identity mapping -->
<id name="Id" unsaved-value="-1">
<column name="Id" />
<generator class="increment" />
</id>
<!-- Simple mappings -->
<property name="Date_Of_Creation" not-null="false">
<column name="Date_Of_Creation"/>
</property>
<property name="Date_Of_Modification" not-null="false">
<column name="Date_Of_Modification"/>
</property>
<many-to-one
name="Last_Modified_By"
class="BusinessObjects.User, NHibernateManyToOne"
column="Last_Modified_By"
cascade="all"
fetch="join"
/>
<many-to-one
name="Last_Session_Id"
class="BusinessObjects.BSession, NHibernateManyToOne"
column="Last_Session_Id"
cascade="all"
not-found="ignore"
fetch="join"
/>
<property name="Name">
<column name="Name"/>
</property>
<property name="Weight" not-null="false">
<column name="Weight"/>
</property>
<property name="Package_Dimension_Length" not-null="false">
<column name="Package_Dimension_Length"/>
</property>
<property name="Package_Dimension_Breadth" not-null="false">
<column name="Package_Dimension_Breadth"/>
</property>
<property name="Package_Dimension_Height" not-null="false">
<column name="Package_Dimension_Height"/>
</property>
<property name="Description" not-null="false">
<column name="Description"/>
</property>
<property name="Image_Location_Large" not-null="false">
<column name="Image_Location_Large"/>
</property>
<property name="Image_Location_Medium" not-null="false">
<column name="Image_Location_Medium"/>
</property>
<property name="Image_Location_Thumbnail" not-null="false">
<column name="Image_Location_Thumbnail"/>
</property>
<property name="Is_Active" not-null="false">
<column name="Is_Active"/>
</property>
<!-- One-to-Many mapping: ProductsPrices-->
<bag name="ProductsPrices" cascade="all">
<key column="Product_Id"/>
<one-to-many class="BusinessObjects.ProductPrice, BusinessObjects"/>
</bag>
<!-- One-to-Many mapping: ProductProductCategories -->
<bag name="ProductCategories" table="dbo.ProductsProductCategories" lazy="false" >
<key column="Product_Id"></key>
<many-to-many
class="BusinessObjects.ProductCategory, BusinessObjects"
column="ProductCategory_Id"
fetch="select"
></many-to-many>
</bag>
<loader query-ref="App_Products_Get_1" />
<!--<sql-insert>exec [App_Product_Save] ?, ?, ?, ?, ?, ?, ?, ?, ?, ? </sql-insert>
<sql-update>exec [App_Product_Save] ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? </sql-update>-->
</class>
<sql-query name="App_Products_Get_1" >
<return alias="" class="BusinessObjects.Product, BusinessObjects">
<return-property name="Id" column="Id"/>
<return-property name="Date_Of_Creation" column="Date_Of_Creation"/>
<return-property name="Date_Of_Modification" column="Date_Of_Modification"/>
<return-property name="Name" column="Name"/>
<return-property name="Weight" column="Weight"/>
<return-property name="Package_Dimension_Length" column="Package_Dimension_Length"/>
<return-property name="Package_Dimension_Breadth" column="Package_Dimension_Breadth"/>
<return-property name="Package_Dimension_Height" column="Package_Dimension_Height"/>
<return-property name="Description" column="Description"/>
<return-property name="Image_Location_Large" column="Image_Location_Large"/>
<return-property name="Image_Location_Medium" column="Image_Location_Medium"/>
<return-property name="Image_Location_Thumbnail" column="Image_Location_Thumbnail"/>
<return-property name="Is_Active" column="Is_Active"/>
</return>
exec [App_Products_Get] :Id, :Date_Of_Creation, :Date_Of_Modification, :Last_Modified_By, :Last_Session_Id, :Name, :Description, :Image_Location_Large, :Image_Location_Medium, :Image_Location_Thumbnail, :Is_Active, :ProductCategory_Id, :Date_Of_Creation_Begin, :Date_Of_Creation_End, :Date_Of_Modification_Begin, :Date_Of_Modification_End
</sql-query>
</hibernate-mapping>
====================================================================================
====================================================================================
Error Stack Trace [IndexOutOfRangeException: Last4_5_0_]
System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName) +4841826
System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) +67
NHibernate.Driver.NHybridDataReader.GetOrdinal(String name) +40
NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name) +74
NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner) +56
NHibernate.Type.ManyToOneType.Hydrate(IDataReader rs, String[] names, ISessionImplementor session, Object owner) +83
NHibernate.Persister.Entity.AbstractEntityPersister.Hydrate(IDataReader rs, Object id, Object obj, ILoadable rootLoadable, String[][] suffixedPropertyColumns, Boolean allProperties, ISessionImplementor session) +1209
NHibernate.Loader.Loader.LoadFromResultSet(IDataReader rs, Int32 i, Object obj, String instanceClass, EntityKey key, String rowIdAlias, LockMode lockMode, ILoadable rootPersister, ISessionImplementor session) +451
NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i, ILoadable persister, EntityKey key, LockMode lockMode, String rowIdAlias, EntityKey optionalObjectKey, Object optionalObject, IList hydratedObjects, ISessionImplementor session) +264
NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters, EntityKey[] keys, Object optionalObject, EntityKey optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session) +480
NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean returnProxies) +409
NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +1287
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +106
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +172
[ADOException: could not execute query
[ exec [App_Products_Get] @p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12, @p13, @p14, @p15 ]
Name:Id - Value:null Name:Date_Of_Creation - Value:null Name:Date_Of_Modification - Value:null Name:Last_Modified_By - Value:null Name:Last_Session_Id - Value:null Name:Name - Value:null Name:Description - Value:null Name:Image_Location_Large - Value:null Name:Image_Location_Medium - Value:null Name:Image_Location_Thumbnail - Value:null Name:Is_Active - Value:1 Name:Date_Of_Creation_Begin - Value:null Name:Date_Of_Creation_End - Value:null Name:Date_Of_Modification_Begin - Value:null Name:Date_Of_Modification_End - Value:null Name:ProductCategory_Id - Value:null
[SQL: exec [App_Products_Get] @p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12, @p13, @p14, @p15]]
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +336
NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) +46
NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes) +155
NHibernate.Loader.Custom.CustomLoader.List(ISessionImplementor session, QueryParameters queryParameters) +52
NHibernate.Impl.SessionImpl.ListCustomQuery(ICustomQuery customQuery, QueryParameters queryParameters, IList results) +259
NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters, IList results) +232
NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters) +229
NHibernate.Impl.SqlQueryImpl.List() +243
DAC.Datafetcher.GetAllProductsSearchResult(Decimal Id, DateTime Date_Of_Creation, DateTime Date_Of_Modification, Decimal Last_Modified_By, Decimal Last_Session_Id, String Name, String Description, String Image_Location_Large, String Image_Location_Medium, String Image_Location_Thumbnail, Boolean Is_Active, DateTime Date_Of_Creation_Begin, DateTime Date_Of_Creation_End, DateTime Date_Of_Modification_Begin, DateTime Date_Of_Modification_End, Decimal ProductCategory_Id) in E:\Development\Source Codes\ECommerce\Persistence\Datafetcher.cs:169
Products.Bind_Grid() in e:\Development\Source Codes\ECommerce\Products.aspx.cs:23
Products.Page_Load(Object sender, EventArgs e) in e:\Development\Source Codes\ECommerce\Products.aspx.cs:74
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627