当前位置: 代码迷 >> ASP.NET >> Nhibernate 调用存储过程解决方案
  详细解决方案

Nhibernate 调用存储过程解决方案

热度:3385   发布时间:2013-02-25 00:00:00.0
Nhibernate 调用存储过程
XML映射:
C# code
<?xml version="1.0" encoding="utf-8"?><hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">  <class name="**.**.**,**.Model" table="Data_CodingContentInfo" lazy="true">    <id type="string" length="50" name="id" column="ID" >      <generator class="assigned" />    </id>    <property type="string" length="50" name="code" column="Code"  />    <property type="string" length="50" name="codinginfoid" column="CodingInfoID"  />    <property type="string" length="50" name="codingcontentcn" column="CodingContentCN"  />    <property type="string" length="50" name="codingcontenten" column="CodingContentEN"  />    <property type="string" length="50" name="adduserid" column="AddUserID"  />    <property type="DateTime" length="23" name="adddate" column="AddDate"  />    <property type="string" length="50" name="edituserid" column="EditUserID"  />    <property type="DateTime" length="23" name="editdate" column="EditDate"  />  </class>  <sql-query name="pro_GetStock ">    <return-scalar column="stocktype" type="string" />    <return-scalar column="drugname" type="string"/>    <return-scalar column="spec" type="string"/>    <return-scalar column="equalcount" type="string"/>    <return-scalar column="baseunit" type="string"/>    <return-scalar column="company" type="string"/>    <return-scalar column="date" type="string"/>    <return-scalar column="id" type="string"/>    <return-scalar column="perprice" type="string"/>    <return-scalar column="batchnumber" type="string"/>    <return-scalar column="innumber" type="string"/>    <return-scalar column="inmoney" type="string"/>    <return-scalar column="outnumber" type="string"/>    <return-scalar column="outmoney" type="string"/>    <return-scalar column="stocknumber" type="string"/>    <return-scalar column="stockmoney" type="string"/>    <return-scalar column="remark" type="string"/>    exec pro_GetStock @where=:where  </sql-query></hibernate-mapping>

调用
C# code
public IList<object[]> GetReport(string where)        {            return Session.GetNamedQuery("pro_GetStock").SetString("where", where).List<object[]>();        }

存储过程返回的是查询的结果集,名字是:pro_GetStock 参数是:@where

现在报错:Named query not known: pro_GetStock 


------解决方案--------------------------------------------------------
自己一般都是把 sessionFactory 的connection 转成相应的数据库连接,再去调用存储过程
------解决方案--------------------------------------------------------
NHibernate 我还真没处理过存储过程 你去看看博客园 李永京的博客里面有写调用存储过程的例子没?
  相关解决方案