Goal: to use Fluent NHibernate in order retrieve the value of a class into a variable by using a stored procedure.
Problem:
using (NHibernate.ISession session = FluentNHibernateHelper.OpenSession())
{
var result = session.CreateSQLQuery("exec test :@data").SetParameter("data", data).AddEntity(typeof(Test));
}
It does not work, what code am I missing in order to retrieve the value of class test in the variable result?
In other words, I would like to retrieve the value that is 1, 2 and asdf in a single class and not list.
I'm using C# code.
Thank you!
CREATE PROCEDURE [dbo].[test]
@data INT
AS
BEGIN
SELECT
1 as a,
2 as b,
'asdf' c
END
GO
C# class:
public class Test
{
public virtual int a { get; set; }
public virtual int b { get; set; }
public virtual string c { get; set; }
}
public class TestMap : ClassMap<Test>
{
public TestMap()
{
Id(x => x.a);
Map(x => x.b);
Map(x => x.c);
}
}
.List<T>().Single();
You have to retrieve all the data and then retrieve a single data.
Not the recommended solution but it solved the case.