Syl*_*via 4 c# entity-framework-6 entity-framework-migrations
我正在使用空迁移来更新我的数据库中的存储过程。存储过程是在数据库的初始创建中添加的自定义存储过程。
我在 DbMigration 类中发现了“AlterStoredProcedure”方法,这可以更新存储过程,但是我必须传递存储过程的参数,并且我想将布尔值和一些整数的默认值设置为空,但我似乎无法让它发挥作用。
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....");
Run Code Online (Sandbox Code Playgroud)
上面的代码产生
ALTER PROCEDURE [dbo].[FT_People_PersonFullTextSearch]
@searchTerm [nvarchar](600),
@isArchived [bit] = 0,
@isActive [bit],
@genderFilter [int],
@rankingFilter [int]
AS
BEGIN
Run Code Online (Sandbox Code Playgroud)
代替
ALTER PROCEDURE [dbo].[FT_People_PersonFullTextSearch]
@searchTerm nvarchar(600),
@isArchived bit = 0,
@isActive bit = null,
@genderFilter int = null,
@rankingFilter int = null
AS
BEGIN
Run Code Online (Sandbox Code Playgroud)
有谁知道如何获取要生产的参数@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....");
Run Code Online (Sandbox Code Playgroud)
请注意,我刚刚将我的解决方案插入到您的示例代码中,我实际上还没有尝试运行这个确切的代码。
我在那里设置的特定参数是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
Run Code Online (Sandbox Code Playgroud)