Alter a view in EntityFramework CF with migration files

c# ef-code-first ef-migrations entity-framework-6 sql

Question

For our project, we are using the Entity Framework (Version 6) with the code first database. So, when we want to change a procedure or a table, we do that in a class and generate a Migration File to update the Database (simple Update-Database in the Paket-Manager window).

If we want to change something that didn't get a class (like a View or a procedure) we change the migration file, which will look like this as an example:

public override void Up()
{
  //Some other code... 

  Sql("ALTER VIEW ExampleView AS Select [Endless Lines of code]");
}

When it comes to bigger views, it gets very messy very fast.

My Question is

Is there a "smart" way to update small things in a procedure or maybe a view (like changing something in the FROM Statement) without creating a whole SQL statement that counts many rows just to do that?

1
0
5/30/2017 9:41:00 AM

Accepted Answer

Not sure what would qualify as "smart", but you can remove the SQL statement clutter from your migration classes by putting them in separate files. This article explains how.

0
5/30/2017 9:54:22 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow