Search code examples
c#sql-servervisual-studio-2017asp.net-core-mvcfluent-nhibernate

How to Retrieve a Single Value from Stored Procedure


Goal:
How to use Fluent Nhibernate in order retrieve the value 1 in a variable by using Stored procedure.

Problem:

        using (NHibernate.ISession session = FluentNHibernateHelper.OpenSession())
        {
            var result = session.CreateSQLQuery("exec test");
        }

It does not work, what code am I missing in order to retrieve the value 1 in the variable result?

I'm using C# and not java code.

Thank you!

CREATE PROCEDURE [dbo].[test]
as  
Begin  

    SELECT 1
End
GO

Solution

  • Does this work?

    var result = session.CreateSQLQuery("exec test").UniqueResult();