如何使用nhibernate调用存储过程?

如何使用nhibernate调用存储过程?,nhibernate,stored-procedures,nhibernate-mapping,Nhibernate,Stored Procedures,Nhibernate Mapping,我对它进行了研究,所有的解决方案都指向一个解决方案,使用下面的代码库并将其放入int.hbm.xml文件。但是我没有。我拥有的是hibernate.cfg.xml和nhvalidator.cfg.xml 我在这里读到: 但是在哪里可以键入查询标记?我在hibernate.cfg.xml中输入了它(见下文),但它不起作用 <?xml version="1.0" encoding="utf-16"?> <hibernate-configuration xmlns="urn:nhib

我对它进行了研究,所有的解决方案都指向一个解决方案,使用下面的代码库并将其放入int.hbm.xml文件。但是我没有。我拥有的是hibernate.cfg.xml和nhvalidator.cfg.xml

我在这里读到: 但是在哪里可以键入查询标记?我在hibernate.cfg.xml中输入了它(见下文),但它不起作用

<?xml version="1.0" encoding="utf-16"?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
        <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
        <property name="connection.connection_string">Server=localhost\MSSQLSERVERR2;Database=SupplierSearch;Trusted_Connection=True</property>
        <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
        <property name="cache.use_minimal_puts">false</property>
        <property name="use_outer_join">false</property>
    </session-factory>
   <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
  namespace="Quarry.SupplierSearch"
  assembly="SupplierSearch">
    <class name="SupplierSearch" table="Client" lazy="true">
      <id name="ClientId" column="ClientId">
        <generator class="native" />
      </id>

      <property name="FirstName" column="FirstName" />
      <property name="ClientId" column="ClientId" />

      <loader query-ref="GetAllClient"/>
    </class>
    <sql-query name="GetAllClient" >
      <return alias="GetAllClient" class="SupplierSearch">
        <return-property name="ClientId" column="ClientId"/>
        <return-property name="FirstName" column="FirstName"/>
      </return>
      exec GetAllClient 
    </sql-query>
  </hibernate-mapping>
</hibernate-configuration>

NHibernate.Connection.DriverConnectionProvider
NHibernate.dialogue.mssql2005dialogue
NHibernate.Driver.SqlClientDriver
Server=localhost\MSSQLSERVERR2;数据库=供应商搜索;可信连接=True
NHibernate.ByteCode.Castle.proxyFactory,NHibernate.ByteCode.Castle
假的
假的
执行GetAllClient
由于它不起作用,我尝试在我的Client.nhv.xml(见下文)中键入它,其中映射了客户机)


exec[GetAllClient]

有什么建议可以让它工作吗?谢谢

它需要被称为
Client.hbm.xml
而不是
Client.hbv.xml
和一个嵌入式资源

编辑我不熟悉任何生成hbv的工具,也从未见过以
开头的映射。必须有一个自定义插件/dll,您必须使用它才能使其正常工作。你在用什么工具


但是,您已经看到了这一点,它可以让SP在没有任何自定义工具的情况下工作。

使用存储过程不受负载收集(仅限标量)的支持。 使用以下格式:

<sql-query name="GetAllClient">
    <load-collection alias="Clients" role ="Client"/>
    SELECT {c.*}
    FROM client c
</sql-query>

选择{c.*}
来自客户端c

(当然,存储过程内部的内容取代了“选择…从…”部分。)

我提到过我的解决方案没有Client.hbm.xml,只有Client.hbv.xml和hibernate.cfg.xml吗?模型层是使用工具生成的,没有生成这样的文件。我尝试添加一个名为client.hbm.xml的新文件作为嵌入式资源,但它返回一个错误,无法查看查询。请查看我的编辑,这里的自定义工具是导致问题的原因。我没有看到你的映射以
开始是的,我在你提供的链接中看到了很多类似的帖子。如果我有client.hmb.xml文件,那就很容易了。不幸的是,没有,客户是使用该工具生成模型层的人,他希望这样。他使用了购买的工具。还有别的办法吗?感谢您的帮助。我怀疑该工具将能够看到SP并正确映射它
<sql-query name="GetAllClient">
    <load-collection alias="Clients" role ="Client"/>
    SELECT {c.*}
    FROM client c
</sql-query>