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?


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]");
}

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.


您可以使用[NotMapped]属性停止将代码优先的类迁移到数据库创建中。

链接地址: http://www.djcxy.com/p/19142.html

上一篇: fastcall:堆栈会发生什么?

下一篇: 使用实体框架忽略为SQL视图创建/更改模型