How to use return code without a result being returned?

Thread is closed for posting
1 posts, 0 answers
  1. Mark
    Mark avatar
    10 posts
    Member since:
    Dec 2012

    Posted 24 Apr 2017 Link to this post

    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"?

Back to Top