How do I return a bit from a stored procedure using nhibernate
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("ContentProviderIm开发者_StackOverflowportLogId", 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>();
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>();
精彩评论