ExecuteSprocAccessor with Output parameter

Topics: Data Access Application Block
Apr 24, 2010 at 9:47 PM

Hello,

in enterprise library 5, does ExecuteSprocAccessor support OUT,OUTPUT parameters from stored procedurs ?

sample:

int? totalRecord = null;
IEnumerable<User> users = db.ExecuteSprocAccessor<User>("GetUsers", totalRecord);

CREATE PROCEDURE [dbo].[GetUsers]
(
 @TotalRecord INT OUTPUT
)
AS
BEGIN
 SELECT @TotalRecord = COUNT(*) FROM dbo.[User]
 
 SELECT * FROM dbo.[User]
END

The value for totalRecord is still null !?

regards

Apr 26, 2010 at 1:58 AM

Hi Hamrosh, it doesn't work that way.  Even in the database.ExecuteNonQuery(storedProcedureName, params object[] parameterValues), you won't be able to get the value of an OUPUT parameter here. You must have a reference to the DbCommand object that was executed and use it in the call to database.GetParameterValue(dbCommand, "TotalRecord");

Here's the related FAQ - http://entlib.codeplex.com/wikipage?title=How%20can%20I%20get%20the%20out%20parameter%20value%20using%20the%20Data%20Access%20Application%20Block%3f&referringTitle=EntLib%20FAQ

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Apr 26, 2010 at 7:09 AM
Edited Apr 26, 2010 at 7:09 AM

Thanks, for the answer, currently i am using the database.ExecuteNonQuery, but what ExecuteSprocAccessor provides is auto map my entity to the IDatareader, i do not need to write the code to do that. thats a great feature if i have it to support multiple result or either the OUT parameters.

Apr 26, 2010 at 7:21 AM

I haven't tried this yet but you can probably create your own extension method that does this.  

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com