Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore create/change of model for a SQL View using Entity Framework

If I create a SQL view and write a model to represent that view I will still want it to map up to be able to read data from the SQL view. The Add-Migration code will see this as a new table because entity framework (version 6) doesn't understand views.

Is there an attribute that I could assign that would prevent migration code from thinking its a new table it needs to create or something in the model builder?

like image 502
Csharpfunbag Avatar asked Feb 25 '14 05:02

Csharpfunbag


2 Answers

add migration nomaly. and after migration rewrite to:

public override void Up()
{
    Sql("CREATE VIEW [viewname] AS SELECT {any select expression} ");
}

public override void Down()
{
    Sql("DROP VIEW [viewname]");
}
like image 194
user5168688 Avatar answered Oct 13 '22 04:10

user5168688


From this SO answer:

Add-Migration IgnoreViewClasses –IgnoreChanges

(Works for EF 4.3.1+)

This creates an empty migration, ignoring any newly created classes from now on.

like image 1
Dunc Avatar answered Oct 13 '22 04:10

Dunc