c#:首先使用OUT Type参数通过EF代码调用存储过程时出错

时间:2016-09-23 14:42:26

标签: c# entity-framework

我正在调用一个存储过程,它有两个参数,其中一个参数不在类型中。

以下是存储过程正文:

[False, False, False, False]

这是我抛出错误的代码:

  

附加信息:参数化查询'(@ CustomerID   bigint,@ Counter int输出)DetailsANDCount @Custome'期待   参数'@CustomerID',未提供。

代码:

CREATE procedure [dbo].[DetailsANDCount] 
    (@CustomerID INT = 0,
     @Counter int OUT)
AS
    IF @CustomerID <= 0
    BEGIN
        SELECT  
            Customers.CustomerID, Customers.FirstName, 
            Customers.LastName, Customers.Address1 
        FROM
            Customers

        SELECT @Counter = COUNT(*) 
        FROM Customers
    END
    ELSE
    BEGIN
        SELECT  
            Customers.CustomerID, Customers.FirstName,  
            Customers.LastName, Customers.Address1 
        FROM
            Customers
        WHERE 
            Customers.CustomerID = @CustomerID

        SELECT @Counter = COUNT(*) 
        FROM Customers
        WHERE Customers.CustomerID = @CustomerID
    END

更新

private async void button3_Click(object sender, EventArgs e)
{
    using (var db = new TestDBContext1())
    {
        SqlParameter param1 = new SqlParameter("@CustomerID", 0);

        var outParam = new SqlParameter();
        outParam.ParameterName = "Counter";
        outParam.SqlDbType = SqlDbType.Int;
        outParam.Direction = ParameterDirection.Output;

        var customers = await db.Database.SqlQuery<Customer>("DetailsANDCount @CustomerID, @Counter OUT", param1, outParam).ToListAsync();
    }
}

修复第二个参数名称后仍然会出现相同的错误。

0 个答案:

没有答案