2

有人用过 context.DataContext.ExecuteStoreQuery 吗?我正在使用 SqlEntityConnection 从这样定义的存储过程中提取数据

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

使用此 F# 代码

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

但我得到了这个例外:

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

4

1 回答 1

0

你试过这个吗?

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

请注意@."@CustomerID"

于 2014-07-26T19:58:43.173 回答