Inside Mendz.Data.Common.ResultInfoExtensions

Mendz.Data.ResultInfo is like a POCO of result information. When used with ADO.Net compatible contexts (like those based on Mendz.Data.Common.DbDataContextBase), ResultInfo can be handy in saving input and output values for the caller. Mendz.Data.Common.ResultInfoExtensions provide a couple of useful shortcuts.

ResultInfoExtensions extends ResultInfo with two static methods: SetInputValues() and SetOutputValues(). Both accept a DbParameterCollection instance, which is looped through to parse out input or output parameters.

In a typical ADO.Net code using stored procedures, the command parameters may be set. These parameters can be accessed from the command as DbParameterCollection. When passed to SetInputValues(), the input parameters are read and added to ResultInfo.InputValues. It is recommended to call this method before calling the command's querying or executing method. Afterwards, the DbParameterCollection can be passed to SetOutputValues(), which parses through the output parameters, which are added to ResultInfo.OutputValues.

SetOutputValues() has a couple of optional parameters to indicate the affectedCountName and the totalCountName. If one of the DbParameterCollection output parameters' name match affectedCountName, the value is stored to ResultInfo.AffectedCount. If the one of the DbParameterCollection output parameters' name match totalCountName, the value is stored to ResultInfo.TotalCount.

Note that ResultInfoExtensions is compatible only for use with DbParameterCollection, which is possible with ADO.Net compatible contexts, like those derived from DbDataContextBase (ex. SqlServerDbDataContext in Mendz.Data.SqlServer).

Get Mendz.Data to build your application's contexts and repositories.

Comments