9

I have found a few articles like this one: http://devtoolshed.com/using-stored-procedures-entity-framework-scalar-return-values

Yet when I take the step to create a function import for a int32 scalar, this is what gets generated:

 public ObjectResult<Nullable<global::System.Int32>> MyStoredProcedure(Nullable<global::System.Int32> orderId)
    {
        ObjectParameter orderIdParameter;
        if (orderId.HasValue)
        {
            orderIdParameter = new ObjectParameter("OrderId", orderId);
        }
        else
        {
            orderIdParameter = new ObjectParameter("OrderId", typeof(global::System.Int32));
        }

        return base.ExecuteFunction<Nullable<global::System.Int32>>("MyStoredProcedure", orderIdParameter);
    }

I am able to call the procedure with this, but am not able to get to the underlying scalar:

ObjectResult<int?> result = myEntities.MyProcedure(orderId);

In the code examples I have seen, I should get context.MyProcedure().SingleOrDefault().

xan
  • 7,440
  • 8
  • 43
  • 65
Roger
  • 2,063
  • 4
  • 32
  • 65

1 Answers1

17

Try this:

int? result = myEntities.MyProcedure(orderId).FirstOrDefault();
Conrad Frix
  • 51,984
  • 12
  • 96
  • 155
prgmrgirl
  • 186
  • 2
  • 3