更改数据库迁移中的存储过程EF 6 Code First – 如何为参数默认传递null

我正在使用空迁移来更新我的数据库中的存储过程。 存储过程是在数据库的初始创建中添加的自定义存储过程。

我在DbMigration类中发现了’AlterStoredProcedure’方法,这可以更新存储过程,但是我必须通过存储过程的参数,我想设置一个布尔值的默认值,并将一些int设置为null,但我似乎无法让这个工作。

AlterStoredProcedure( name: "[dbo].[FT_People_PersonFullTextSearch]", parametersAction: p => new { searchTerm = p.String(600), isArchived = p.Boolean(false), isActive = p.Boolean(null), genderFilter = p.Int(null), rankingFilter = p.Int(null) }, body: "the body of my stored proc...."); 

上面的代码产生

 ALTER PROCEDURE [dbo].[FT_People_PersonFullTextSearch] @searchTerm [nvarchar](600), @isArchived [bit] = 0, @isActive [bit], @genderFilter [int], @rankingFilter [int] AS BEGIN 

代替

 ALTER PROCEDURE [dbo].[FT_People_PersonFullTextSearch] @searchTerm nvarchar(600), @isArchived bit = 0, @isActive bit = null, @genderFilter int = null, @rankingFilter int = null AS BEGIN 

有谁知道如何获取参数来生成@isActive bit = null

我正在使用Entity Framework 6.1.1,我可以通过执行以下操作来实现此目的:

 AlterStoredProcedure( name: "[dbo].[FT_People_PersonFullTextSearch]", parametersAction: p => new { searchTerm = p.String(600), isArchived = p.Boolean(false), isActive = p.Boolean(null, "null"), genderFilter = p.Int(null, "null"), rankingFilter = p.Int(null, "null") }, body: "the body of my stored proc...."); 

请注意,我刚刚将我的解决方案插入到您的示例代码中,我实际上没有尝试运行这个确切的代码。

我在那里设置的具体参数是defaultValueSql: "null"

这给了我一个看起来像这样的存储过程:

 ALTER PROCEDURE [dbo].[FT_People_PersonFullTextSearch] @searchTerm nvarchar(600), @isArchived bit = 0, @isActive bit = null, @genderFilter int = null, @rankingFilter int = null AS BEGIN