How to return a bit from a stored procedure using nhibernate

I use nHibernate in my project, but I have a stored procedure that just returns boolen of success or now.

How to do it in C #?

I tried the following, but I do not like it, because I do not 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>();

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>();
+3
source share
1 answer

I would solve this problem a little differently, which I hope will serve as a workaround for you.

I would modify my stored procedure to return 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>();
+5
source

Source: https://habr.com/ru/post/1743225/


All Articles