我尝试使用DbMigration.CreateStoredProcedure
创建一个取整数InvoiceId
并返回小数的函数。但是,当我应用迁移时,我收到此错误:
必须声明标量变量" @ InvoiceId"。
这是EF迁移代码:
CreateStoredProcedure("SumInvoiceTransactions", b => b.Decimal(9, 2),
"RETURN (SELECT SUM(Amount) FROM Transactions WHERE InvoiceId=@InvoiceId)");
这是等效的SQL代码:
CREATE FUNCTION SumInvoiceTransactions(@InvoiceId int) RETURNS decimal
AS BEGIN
RETURN (SELECT sum(Amount) FROM Transactions WHERE InvoiceId=@InvoiceId)
END
如何声明参数?
答案 0 :(得分:2)
就像那样:
CreateStoredProcedure("SumInvoiceTransactions", c => new { InvoiceId = c.Int() },
"RETURN (SELECT SUM(Amount) FROM Transactions WHERE InvoiceId=@InvoiceId)");