Entity Framework scalar value from stored procedure

entity-framework stored-procedures

Question

Similar items may be found elsewhere: http://devtoolshed.com/using-stored-procedures-entity-framework-scalar-return-values

However, when I go to make a function import for an int32 scalar, the following is what is produced:

 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);
    }

With this, I can invoke the process, but I can't access the underlying scalar:

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

The code samples I've seen suggest that I should acquirecontext.MyProcedure().SingleOrDefault() .

1
9
12/18/2012 4:33:55 PM

Accepted Answer

Do this:

int? result = myEntities.MyProcedure(orderId).FirstOrDefault();
15
1/29/2013 8:59:15 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow