I am using entity framework and Codefirst to create a Stored procedure. As I reed, we should do some steps in package manager to create SP.
1 - enable migration
2- add-migration MYclass
3- update-database
and in Myclass(new created)
I write my SP code in UP() method to create SP. works fine!! BUT when I change SP and run update-database again it does not work and I need to do another add-migration command to create new MYclass2. Is that right? I mean every time I should write add-migration?
this is mycode
public override void Up()
{
Sql(@"Create procedure testSp
as
select std.Id as stdName, std.Name as MajorName, mj.Name from dbo.Students as std
inner join dbo.Majors as mj on std.Id = mj.Id
");
}
public override void Down()
{
Sql("drop procedure testSp");
}
when I run update-database again the result is "No pending explicit migration"
even if I change the SQL query to "Alter procedure...." it does not work , no change happens. thanks
EDITED
consider this scenario, I want to change my SP name(just an example) so I need to change the query to "Alter store procedure tespSP2 ..." or any other change, should I run add-migration again?? or update-database is supposed to do it??
in entity framework migrations added to a _migrationHistory table, you can delete the last row of this table [it's not recommended]
or you can use rollback/undo command
Update-Database -TargetMigration:MigrationsName
then use update-database -force