本文介绍了如何将参数传递给DbMigration.Sql()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用实体框架迁移时, DbMigration
基类
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"
}
);
错误结果
System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@Name"
这个语句的正确语法是什么?
What's the correct syntax of this statement?
推荐答案
我挖掘了EF源代码,似乎这个参数(或者说是从它创建的 MigrationOperation.AnonymousObject
属性)根本不使用!
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!
这篇关于如何将参数传递给DbMigration.Sql()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!