F# context.DataContext.ExecuteStoreQuery

195 views Asked by At

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.

1

There are 1 answers

1
Mark Seemann On

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