Fluent NHibernate to query stored procedure without an hbm.xml mapping

rahul picture rahul · May 7, 2013 · Viewed 14.5k times · Source

Is there any way to query stored procedure in Fluent Nhibernate without creating an hbm.xml file mapping?

Answer

icepicker picture icepicker · Jul 15, 2013

I assume you use the standard

Session.GetNamedQuery(....

instead, you can use

var result = Session.CreateSQLQuery("exec MyStoredProc :pUserId, :pIsLocked")
                    .AddEntity(typeof(MyDomainObject))
                    .SetParameter("pUserId", userId)
                    .SetParameter("pIsLocked", isLocked)
                    .List<MyDomainObject>();

This allows you to call the stored proc but still get back a domain object (or list of) without needing a .hbm.xml file.

Actually there's this post