使用 Nhibernate 调用存储过程 - 出现异常 无持久化:

发布于 2024-08-29 21:14:28 字数 1035 浏览 3 评论 0原文

这是代码,我如何调用存储过程

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

XML 映射

<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>

类映射

public virtual Int32 Tot {get { return _Tot; } set { _Tot = value; } }
    public virtual Int32 subtot { get { return _subtot; } set { _subtot = value; }}

我遇到异常: No persister for: ReleaseDAL.ProgressBar, ReleaseDAL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

请告诉我这里有什么问题吗?

谢谢

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; } 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七度光 2024-09-05 21:14:28

您可能会收到错误消息,因为您没有将映射文件标记为嵌入资源。请首先检查这一点。

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

£烟消云散 2024-09-05 21:14:28

好吧,您没有 ProgressBar 的映射(我认为它不是一个实体),所以您可能只需要一个 DTO 作为查询的结果。

因此,您只需将结果映射为标量,并在查询中定义一个转换器。

 <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>

并在查询方法中:

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

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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文