NHibernate的什么也没有,但存储过程 [英] NHibernate with nothing but stored procedures

查看:136
本文介绍了NHibernate的什么也没有,但存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有NHibernate的调用存储过程时ISession.Get被称为其键,而不是使用动态SQL来获取一个实体。

I'd like to have NHibernate call a stored procedure when ISession.Get is called to fetch an entity by its key instead of using dynamic SQL.

我们有一直使用NHibernate和允许它产生我们对查询和插入/更新/删除的SQL,但现在可具有到应用程序部署到要求我们使用存储的过程对所有的数据库访问的环境。我们可以使用SQL插入,SQL更新,并在我们的.hbm.xml映射文件的SQL删除插入/更新/删除。我们的HQL和标准的查询必须与存储过程调用所取代。

We have been using NHibernate and allowing it to generate our SQL for queries and inserts/updates/deletes, but now may have to deploy our application to an environment that requires us to use stored procedures for all database access. We can use sql-insert, sql-update, and sql-delete in our .hbm.xml mapping files for inserts/updates/deletes. Our hql and criteria queries will have to be replaced with stored procedure calls.

不过,我还没有想出如何强制NHibernate的使用自定义存储过程来取出其关键实体。我还是想能够调用ISession.Get,如:

However, I have not figured out how to force NHibernate to use a custom stored procedure to fetch an entity by its key. I still want to be able to call ISession.Get, as in:

using (ISession session = MySessionFactory.OpenSession())
{
    return session.Get<Customer>(customerId);
}

和也懒加载的对象,但我想NHibernate的叫我GetCustomerById存储,而不是生成动态SQL过程。

and also lazy load objects, but I want NHibernate to call my "GetCustomerById" stored procedure instead of generating the dynamic SQL.

可以这样做?

也许NHibernate的不再是适当的情况这个新的环境中,我们必须支持。

Perhaps NHibernate is no longer a fit given this new environment we must support.

推荐答案

我没有尝试过自己,但你可能想寻找到的本地SQL和自定义装载机的概念。

I've not tried it myself but you might want to looking into native sql and custom loader concept.

下面是一个好文章由Ayende Rahien:使用NHibernate使用存储过程

Here's a good article by Ayende Rahien: Using NHibernate With Stored Procedures

下面是另一种更易于理解的基础上NH beta版由斯科特·麦克马斯特版:的储存在NHibernate的

Here's another easier-to-understand version by Scott McMaster based on NH beta version: Stored Procedures in NHibernate

这篇关于NHibernate的什么也没有,但存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆