2

Has anyone used context.DataContext.ExecuteStoreQuery? I am using the SqlEntityConnection to pull data from a stored procedure defined as such

CREATE PROCEDURE [dbo].[CustOrderHist] @CustomerID nchar(5)
AS
SELECT ProductName, Total=SUM(Quantity)
FROM Products P, [Order Details] OD, Orders O, Customers C
WHERE C.CustomerID = @CustomerID
AND C.CustomerID = O.CustomerID AND O.OrderID = OD.OrderID AND OD.ProductID = P.ProductID
GROUP BY ProductName

With this F# code

let RunCustomerStoredProcedure () =
    let context = schema.GetDataContext()
    let query = context.DataContext.ExecuteStoreQuery("CustOrderHist",new SqlParameter("CustomerID","AFKLI"))
    query |> Seq.iter(fun (pn,t) -> Console.WriteLine(String.Format("{0} {1}",pn,t)))

but I am getting this exception:

Procedure or function 'CustOrderHist' expects parameter '@CustomerID', which was not supplied.

ildjarn
  • 62,044
  • 9
  • 127
  • 211
Jamie Dixon
  • 4,204
  • 4
  • 25
  • 47

1 Answers1

0

Have you tried this?

let RunCustomerStoredProcedure () =
    let context = schema.GetDataContext()
    let query =
        context.DataContext.ExecuteStoreQuery(
            "CustOrderHist",
            new SqlParameter("@CustomerID","AFKLI"))
    query |> Seq.iter(fun (pn,t) -> Console.WriteLine(String.Format("{0} {1}",pn,t)))

Notice the additional @ in "@CustomerID".

Mark Seemann
  • 225,310
  • 48
  • 427
  • 736