entity framework - Update stored procedure in Code First DbMigration -
i have solution stored procedures creation in answer https://stackoverflow.com/a/15171900.
i running
sql(properties.resources.create_sp_dosomething);
in initial dbmigration.
my sql scripts have code first drop existing sp , create new updated sp. whene run
sql(properties.resources.create_sp_dosomething);
in new dbmigration, , logic inside sp changed works fine.
the problem arise when want update stored procedure columns (lets isactive) added model in later commits, , updating without existing db (so new db created). fails
invalid column name 'isactive'.
any solution other removing existing calls to
sql(properties.resources.create_sp_dosomething);
and have in newest dbmigration.
separate stored procedures model creation doing stored procedure updates in migration seed() method runs after migrations:
context.database.executesqlcommand(sp_dosomething);
since runs every update-database, need make script idempotent adding existance check start of create_sp_dosomething:
if exists (select * sys.objects type = 'p' , name = 'sp_dosomething') begin drop procedure sp_dosomething end
Comments
Post a Comment