开发者

Calling Stored procedure using Nhibernate -- Getting exception No persister for:

开发者 https://www.devze.com 2022-12-27 12:03 出处:网络
here is code, how I am calling Stored procedure ISession session = NHibernateHelper.GetCurrentSession();

here is code, how I am calling Stored procedure

ISession session = NHibernateHelper.GetCurrentSession();
        IQuery q = session.GetNamedQuery("ps_getProgressBarData1");
        var t = q.List();

XML mapping

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"   namespace="ReleaseDAL"  assembly="ReleaseDAL">

 <sql-query name="ps_getProgressBarData1">
    <return alias="ProgressBar" class="ProgressBar">
      <return-property name="Tot" column="Tot"/>
      <return-property name="subtot" column="subtot"/>
    </return>
    exec ps_getProgressBarData1
  </sql-query>
</hibernate-mapping>

Class mapping

public virtual Int32 Tot {get { return _Tot;开发者_如何学Python } set { _Tot = value; } }
    public virtual Int32 subtot { get { return _subtot; } set { _subtot = value; }}

I am getting exception: No persister for: ReleaseDAL.ProgressBar, ReleaseDAL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Please tell me what is the issue here?

Thanks


You could get that error you don't have the mapping file marked as embedded resource. Please check that as first thing.


Well you don't have a mapping for ProgressBar (it's not an entity I suppose), so probably you just want a DTO as a result from the query.

So you just have to map the result as scalars, and in the query define a transformer.

 <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="ReleaseDAL"  assembly="ReleaseDAL">

 <sql-query name="ps_getProgressBarData1">
      <return-scalar column="Tot" Type="xxx"/>
      <return-scalar column="subtot" Type="xxx"/>

    exec ps_getProgressBarData1
  </sql-query>
</hibernate-mapping>

and in the query methode:

query.SetResultTransformer(Transformers.AliasToBean(typeof(ProgressBar )));
query.List()
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号