Like that:
CreateStoredProcedure("SumInvoiceTransactions", c => new { InvoiceId = c.Int() },
"RETURN (SELECT SUM(Amount) FROM Transactions WHERE InvoiceId=@InvoiceId)");
Domanda
I'm trying to use DbMigration.CreateStoredProcedure
to create a function that takes an integer InvoiceId
and returns a decimal. However, when I apply the migration, I get this error:
Must declare the scalar variable "@InvoiceId".
This is the EF migration code:
CreateStoredProcedure("SumInvoiceTransactions", b => b.Decimal(9, 2),
"RETURN (SELECT SUM(Amount) FROM Transactions WHERE InvoiceId=@InvoiceId)");
This is the equivalent SQL code:
CREATE FUNCTION SumInvoiceTransactions(@InvoiceId int) RETURNS decimal
AS BEGIN
RETURN (SELECT sum(Amount) FROM Transactions WHERE InvoiceId=@InvoiceId)
END
How do I declare the parameter?
Soluzione
Like that:
CreateStoredProcedure("SumInvoiceTransactions", c => new { InvoiceId = c.Int() },
"RETURN (SELECT SUM(Amount) FROM Transactions WHERE InvoiceId=@InvoiceId)");