使用 Fluent nHibernate 删除的存储过程

发布于 2024-10-17 10:54:09 字数 154 浏览 0 评论 0原文

我已经看过有关该主题的其他一些帖子,但大多数似乎都在处理选择。我有一个存储过程,它执行大量删除和检查,并且仅接受一个 int 作为参数,并返回一点以表示成功。我想使用来自锐利架构的流畅 nHibernate 从我的代码中启动它。

关于如何最好地解决这个问题有什么想法吗? 谢谢

I've had a look at some of the other posts on the topic but most seem to be dealing with selects. I've got a stored procedure that does a number of deletes and checks and simply takes in one int as an argument and returns a bit for success. I want to fire this off from my code using fluent nHibernate from sharp architecture.

Any Ideas on how best to tackle this?
Thanks

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

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

发布评论

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

评论(1

温折酒 2024-10-24 10:54:09

您还无法使用 FluentNHibernate 映射存储过程(AFAIK)。您需要这样的 xml 映射 (SQL-Server):

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Your.Xml.Mappings.Namespace">
  <sql-query name="DeleteSomeEntity" >
    exec dbo.deleteSomeEntityProc ?
  </sql-query>
</hibernate-mapping>

如果您使用 NHibernate 调用它,返回值可能是 object[]ArrayList。注意“?”参数,它将获取你的 id。调用的名称将为“DeleteSomeEntity”。另请记住,您必须使用约定“.hbm.xml”来命名该文件,并且需要将其作为嵌入式资源包含在您的项目中!

为了让 FluentNHibernate 加载该文件,您需要

database = database.Mappings(m => m.HbmMappings.AddFromAssembly(assembly));

在初始化映射时调用调用 xml 的程序集。

当您确实需要映射的返回类型时,可以在映射中包含 声明。不过我还没有这样做,你必须在 NHibernate 参考手册中查找它。

HTH。

You cannot map stored procedures with FluentNHibernate yet (AFAIK). You need an xml mapping like this (SQL-Server):

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Your.Xml.Mappings.Namespace">
  <sql-query name="DeleteSomeEntity" >
    exec dbo.deleteSomeEntityProc ?
  </sql-query>
</hibernate-mapping>

The return value will probably be an ArrayList of object[] if you call it with NHibernate. Notice the '?' argument, which will take your id. The name to call will be "DeleteSomeEntity" Also remember, that you'll have to name the file with the convention ".hbm.xml" and you need to include it as an embedded resource in your project!

For FluentNHibernate to load the file, you'll need to call

database = database.Mappings(m => m.HbmMappings.AddFromAssembly(assembly));

on the assembly calling the xml when initializing your mappings.

When you really need the return-type mapped, you can include a <return> or <return-property> declaration in the mapping. I haven't done this, though, you'd have to look it up in the NHibernate reference manual.

HTH.

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