Alter Stored Procedure in DB Migration EF 6 Code First - how to pass default null for parameter

I am using Empty Migration to update a stored procedure in my database. A stored procedure is a custom stored process that was added when the database was created.

I found the "AlterStoredProcedure" method in the DbMigration class and this works to update the stored procedure, however I need to go through the stored procedure parameters and I want to set the default value for the boolean and some ints to null, but I can not get this to work.

    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....");

In the above code

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

instead

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

Does anyone know how to get the parameters to create @isActive bit = null?

+4
1

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
+4

Source: https://habr.com/ru/post/1539566/


All Articles