1.Database platform: SqlServer
2.Data Access: nHibernate 1.2
Now we need access the store procedure by nHibernate,like this:
ALTER PROCEDURE TestProc()
AS
BEGIN
Select * From User
Return 1234
END
I know I can get the User List by IQuery, And I want to get the default return value "1234" too.
Question:
- How to get this default return value?
- If can't get it directly , can we get the value by output parameter?
I've done this before (not in nHibernate).
You must completely process the entire recordset before retrieving the output parameters.
Another discussion
this is how i do it:
in my .hbm.xml
in my repository.cs
First of all, that's not called a "default return value" anywhere I've ever seen. It's just the return value. It's usually used to return a success / error status.
I don't know how nHibernate does things, but in ADO.NET, you'd use a parameter with the Direction property set to "Return". Maybe there's an equivalent in nHibernate.
OTOH, it would be more usual to use an OUTPUT parameter to return an actual useful value, and keep the RETURN value for error codes, or for being ignored.
NHibernate does not let you use stored procedures in this manner. But it does allow a way to make calls using the plain old ADO.NET API. The NHibernate Documentation says that if you want to use these procedures you have to execute them via session.Connection. Here's an example -
You can find more details here -
http://refactoringaspnet.blogspot.com/2009/06/how-to-use-legacy-stored-procedures-in.html