This is a migrated thread and some comments may be shown as answers.

How to use return code without a result being returned?

0 Answers 31 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mark
Top achievements
Rank 1
Mark asked on 24 Apr 2017, 02:38 PM

Is it possible to wire up a stored proc that may or may not return a result, but does return a return code?  E.g. a trivial example is proc that does an update, and returns a result shape with a single ID column, but also returns a return code.  In the scenario where the proc fails I don't want to to return a result shape, just the return code. 

For example, the dynamically generated .cs file for the .rlinq model defines the query like this:

IEnumerable<UpdateSomethingResult> queryResult = this.ExecuteQuery<UpdateSomething>("[dbo].[UpdateSomething]", CommandType.StoredProcedure, parameterName, parameterDescription, parameterReturnValue);

returnValue = parameterReturnValue.Value == DBNull.Value ? -1: (int)parameterReturnValue.Value;

At the moment if I don't return a result shape I get the dreaded "Object reference not set to instance of object" error, because Data Access is expecting a result but nothing is being return from the proc call.  Is there a way to make the result "optional"?

Tags
General Discussions
Asked by
Mark
Top achievements
Rank 1
Share this question
or