Reputation: 4593
I have a view
[Table("View1")]
public class View1Model
{
[Key]
public int Id { get; set; }
public int Age { get; set; }
}
I would like to add another public int Weight to the table because in the sql database i updated the view, however the migration wont work.
It says when i try to update database that
Cannot alter 'dbo.View1' because it is not a table.
I know that i can remove the 'table' attribute but that will not work because i need to check in my code.Out of the question
Upvotes: 3
Views: 2296
Reputation: 381
When you add-migration
it will try to AddColumn()
in the Up()
and DropColumn()
in the Down()
. You'll want to remove those lines from the migration and manually change the view with a Sql(@"ALTER VIEW ...")
command in which you modify the view directly in SQL. This will accomplish what the automatic migration was trying to do.
Upvotes: 7