tags:

views:

145

answers:

1

I am using nHibernate in my project but I have a stored procedure which just returns a boolen of success or now.

How do I code this in c#?

I have tried the following but it doesnt like cause I dont have a mapping for bool!!!

{"No persister for: System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"}

IQuery query = NHibernateSession.CreateSQLQuery("EXEC MyDatabase.dbo.[ContentProvider_Import] :ContentProviderImportLogId", "success", typeof(bool))
                .SetInt32("ContentProviderImportLogId", log.Id);

            var test = query.UniqueResult<bool>();

and the same result from

IQuery query = NHibernateSession.CreateSQLQuery("EXEC MyDatabase.dbo.[ContentProvider_Import] :ContentProviderImportLogId")
                .AddEntity(typeof(bool))
                .SetInt32("ContentProviderImportLogId", log.Id);

            var test = query.UniqueResult<bool>();
A: 

I would have tackled this problem in a slightly different way which will hopefully serve as a workaround for you.

I would change my stored procedure to return a bool as follows:

declare @result bit
set @result = 1

select @result

Then the C# code will be:

IQuery query = NHibernateSession.CreateSQLQuery("EXEC MyDatabase.dbo.[ContentProvider_Import] :ContentProviderImportLogId")
                .SetInt32("ContentProviderImportLogId", log.Id);

var test = query.UniqueResult<bool>();
s1mm0t
thanks s1mm0t but thats exactly what I've tried, I jsut get an error saying I havent declared the return types
tigermain
Not sure what your problem is then. Before I posted my answer, I tried this and it worked fine. I'm running version 2.1.2.4000 of NHibernate are you using an older version? Also, from the way you are calling the SP, it appears that you are using SQLServer which is what I tested against (2008) if you're not, then this could be another reason why it isn't working.
s1mm0t
I'll copy and paste just to make sure.....
tigermain
Sorry following error:{"Return types of SQL query were not specified [EXEC MyDatabase.dbo.[ContentProvider_Import] :ContentProviderImportLogId]"}
tigermain