Ashwin-

To be honest, I don't know if you have to map every column, but the
columns you do want need to be in the correct order and have the same
column name as the result set from the proc.


On Apr 5, 10:46 pm, Ashwin <[email protected]> wrote:
> Chris,
>
> Thanks for the reply...
>
> Does it mean I have to map each and every column to the class property
> names?
>
> Thanks,
> Ashwin
>
> On Apr 5, 11:40 pm, Chris J <[email protected]> wrote:
>
> > I have run into this exception when there is a mismatch between the
> > column names of the stored proc result data (in your case it would be
> > the Load table columns) and the column mapping in the result class
> > (FDDataTransfer.Load).
>
> > On Apr 5, 8:32 pm, Ashwin <[email protected]> wrote:
>
> > > Hello,
>
> > > I am trying to use a very simple stored procedure with Nhibernate and
> > > I get the follwoing error
>
> > > Description: An unhandled exception occurred during the execution of
> > > the current web request. Please review the stack trace for more
> > > information about the error and where it originated in the code.
>
> > > Exception Details: System.IndexOutOfRangeException: [LoadID]
>
> > > Stack Trace:
>
> > > [IndexOutOfRangeException: [LoadID]]
> > >    System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String
> > > fieldName) +4841162
> > >    System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) +67
> > >    NHibernate.Driver.NHybridDataReader.GetOrdinal(String name) +13
> > >    NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String
> > > name) +47
> > >    NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[]
> > > names, ISessionImplementor session, Object owner) +31
> > >    NHibernate.Loader.Loader.GetKeyFromResultSet(Int32 i,
> > > IEntityPersister persister, Object id, IDataReader rs,
> > > ISessionImplementor session) +88
> > >    NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet,
> > > ISessionImplementor session, QueryParameters queryParameters,
> > > LockMode[] lockModeArray, EntityKey optionalObjectKey, IList
> > > hydratedObjects, EntityKey[] keys, Boolean returnProxies) +89
> > >    NHibernate.Loader.Loader.DoQuery(ISessionImplementor session,
> > > QueryParameters queryParameters, Boolean returnProxies) +704
>
> > > NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImp
> > >  lementor
> > > session, QueryParameters queryParameters, Boolean returnProxies) +70
> > >    NHibernate.Loader.Loader.DoList(ISessionImplementor session,
> > > QueryParameters queryParameters) +102
>
> > > [ADOException: could not execute query
> > > [ exec dbo.LoadsbyZipcode_Get @p0 ]
> > >   Name:ZipCode - Value:1
> > > [SQL: exec dbo.LoadsbyZipcode_Get @p0]]
> > >    NHibernate.Loader.Loader.DoList(ISessionImplementor session,
> > > QueryParameters queryParameters) +196
> > >    NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor
> > > session, QueryParameters queryParameters) +18
> > >    NHibernate.Loader.Loader.List(ISessionImplementor session,
> > > QueryParameters queryParameters, ISet`1 querySpaces, IType[]
> > > resultTypes) +79
> > >    NHibernate.Loader.Custom.CustomLoader.List(ISessionImplementor
> > > session, QueryParameters queryParameters) +19
> > >    NHibernate.Impl.SessionImpl.ListCustomQuery(ICustomQuery
> > > customQuery, QueryParameters queryParameters, IList results) +159
> > >    NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec,
> > > QueryParameters queryParameters, IList results) +156
> > >    NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec,
> > > QueryParameters queryParameters) +159
> > >    NHibernate.Impl.SqlQueryImpl.List() +159
> > >    FreightDaddy.LoadSearchResults.Page_Load(Object sender, EventArgs
> > > e) in C:\Ashwin - Docs\Projects\FreightDaddy\FreightDaddy\FreightDaddy
> > > \LoadSearchResults.aspx.cs:30
> > >    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
>
> > > Here is the stored proc
>
> > > ALTER PROCEDURE [dbo].[LoadsbyZipcode_Get]
>
> > >   @ZipCode int
> > >   -...@radius int
>
> > > AS
> > > BEGIN
>
> > >         if ( @ZipCode = 1 )
> > >         SELECT * FROM dbo.[Load]
>
> > > END
>
> > > Its simple for the time being but will get more complicated later on.
>
> > > And here is the mappping in the Load.hbm.xml
>
> > > <sql-query name="LoadsbyZipcode_Get">
> > >     <return class="FDDataTransfer.Load,FDDataTransfer" />
> > >     exec dbo.LoadsbyZipcode_Get :ZipCode
> > >   </sql-query>
>
> > > and here is the code which is trying to access the stored proc
>
> > > NHibernate.IQuery query =
> > > _session.GetNamedQuery("LoadsbyZipcode_Get");
> > > query.SetInt32("ZipCode", 1);
>
> > > Not sure what is going on here...
>
> > > Hoping for some help.
>
> > > Ash
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to