NHibernate GetNamedQuery can not execute stored procedure -
so have stored procedure named get_by_cat_and_tag
, should return table ms
, , in c# code should return list of ms
objects, ms.hbm.xml
contains following:
<sql-query name="get_by_cat_and_tag"> <!-- return type must nhibernate mapped entity --> <return class="ms"> <return-property column="id" name="id" /> <return-property column="filename" name="filename" /> <return-property column="displaytitle" name="displaytitle" /> <return-property column="isenabled" name="isenabled" /> <return-property column="mediatype" name="mediatype" /> <return-property column="priority" name="priority" /> <return-property column="datecreated" name="datecreated" /> <return-property column="datelastmodified" name="datelastmodified" /> <return-property column="description" name="description" /> <return-property column="imagepath" name="imagepath" /> </return> <!--exec get_by_cat_and_tag@categoryid=:catid, @tagid=:tid--> exec get_by_cat_and_tag:catid, :tid </sql-query>
all column names returned stored procedure correct , ease made them same.
the data access layer contains call stored procedure:
var query = session.getnamedquery("get_by_cat_and_tag") .setparameter("catid", categoryid).setparameter("tid", tagid) .list<ms>();
the exception message:
could not execute query [ exec get_by_cat_and_tag @p0, @p1 ] name:catid - value:130 name:tid - value:449 [sql: exec get_by_cat_and_tag @p0, @p1] stack trace: @ system.data.sqlclient.sqldatareader.getordinal(string name) @ nhibernate.type.nullabletype.nullsafeget(idatareader rs, string name) @ nhibernate.loader.loader.getinstanceclass(idatareader rs, int32 i, iloadable persister, object id, isessionimplementor session) @ nhibernate.loader.loader.instancenotyetloaded(idatareader dr, int32 i, iloadable persister, entitykey key, lockmode lockmode, string rowidalias, entitykey optionalobjectkey, object optionalobject, ilist hydratedobjects, isessionimplementor session) @ nhibernate.loader.loader.getrow(idatareader rs, iloadable[] persisters, entitykey[] keys, object optionalobject, entitykey optionalobjectkey, lockmode[] lockmodes, ilist hydratedobjects, isessionimplementor session) @ nhibernate.loader.loader.getrowfromresultset(idatareader resultset, isessionimplementor session, queryparameters queryparameters, lockmode[] lockmodearray, entitykey optionalobjectkey, ilist hydratedobjects, entitykey[] keys, boolean returnproxies) @ nhibernate.loader.loader.doquery(isessionimplementor session, queryparameters queryparameters, boolean returnproxies) @ nhibernate.loader.loader.doqueryandinitializenonlazycollections(isessionimplementor session, queryparameters queryparameters, boolean returnproxies) @ nhibernate.loader.loader.dolist(isessionimplementor session, queryparameters queryparameters)
any appreciated.
you missing space after word tag:-
exec get_by_cat_and_tag:catid, :tid
should be:-
exec get_by_cat_and_tag :catid, :tid
also note columns returned must match in case, worth checking one.
Comments
Post a Comment