How to pass parameters to DbMigration.Sql() Method
-
21-12-2019 - |
Question
When using Entity Framework Migrations, the DbMigration
base class has a Sql method which takes parameters in an anonymous object
I cannot for the life of me figure out how to use it.
Sql(@"
UPDATE dbo.SlideSets
SET Name = @Name,
", false, new {
Name = "Foo"
}
);
Results in the error
System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@Name"
What's the correct syntax of this statement?
Solution
I dug into the EF source code and it seems that this parameter (or rather the MigrationOperation.AnonymousObject
property that's created from it) is not used at all!
I've created a ticket on their issue tracker to either do something about it or remove the api
OTHER TIPS
The standard generator for MSSQL is doing nothing with the anonymous object in this case. You need to put the parameter directly into command. Or you can derive your own and handle it.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow