문제

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?

도움이 되었습니까?

해결책

Like that:

CreateStoredProcedure("SumInvoiceTransactions", c => new { InvoiceId = c.Int() },
"RETURN (SELECT SUM(Amount) FROM Transactions WHERE InvoiceId=@InvoiceId)");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top