所以我有一個存儲過程命名get_by_cat_and_tag
,它應該返回表MS
,並在我的C#代碼,它應該返回MS
對象,其中MS.hbm.xml
包含以下列表:NHibernate的GetNamedQuery不能執行存儲過程
<sql-query name="get_by_cat_and_tag">
<!-- return type must be an 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 [email protected]=:catId, @tagId=:tId-->
exec get_by_cat_and_tag:catId, :tId
</sql-query>
從這個存儲過程返回的所有列名是否正確,並便於我讓他們一樣。
數據訪問層包含該呼叫到存儲過程:
var query = session.GetNamedQuery("get_by_cat_and_tag")
.SetParameter("catId", categoryId).SetParameter("tId", tagId)
.List<MS>();
異常消息:
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]
The stack trace:
at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name)
at NHibernate.Loader.Loader.GetInstanceClass(IDataReader rs, Int32 i, ILoadable persister, Object id, ISessionImplementor session)
at NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i, ILoadable persister, EntityKey key, LockMode lockMode, String rowIdAlias, EntityKey optionalObjectKey, Object optionalObject, IList hydratedObjects, ISessionImplementor session)
at NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters, EntityKey[] keys, Object optionalObject, EntityKey optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session)
at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
任何幫助理解。
是否'get_by_cat_and_tag(130,449)'當數據庫中直接調用工作?你測試過了嗎? – acdcjunior 2013-05-04 07:25:58
@acdcjunior:它不返回預期的記錄,是 – MoB 2013-05-04 07:31:55