2011-11-22 27 views
6

Tôi đã tìm thấy một vài bài như thế này một: http://devtoolshed.com/using-stored-procedures-entity-framework-scalar-return-valuesGiá trị vô hướng từ thủ tục lưu trữ qua Entity Framework

Tuy nhiên, khi tôi thực hiện bước để tạo ra một khẩu chức năng cho một vô hướng int32, đây là những gì được tạo ra:

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

tôi có thể gọi thủ tục với điều này, nhưng tôi không thể nhận được đến vô hướng cơ bản:

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

Trong các ví dụ mã tôi đã thấy, tôi sẽ nhận được context.MyProcedure().SingleOrDefault().

Trả lời

12

Hãy thử cách này:

int? result = myEntities.MyProcedure(orderId).FirstOrDefault(); 
Các vấn đề liên quan