开发者

Stored Procedures to delete with Fluent nHibernate

I've had a look at some of the other posts on开发者_StackOverflow 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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜