Generating a SQL view from EF 6.1 code first

ぃ、小莉子 提交于 2019-12-21 13:43:30

问题


I just changed my application from Database first to code first! What a great improvement in deploying!. But now i have the following problem. I generated my Code-first model from my database, but after recreating the database from the generated code, my views from my database are generated like tables!

How do I generate my views from code first? and/or map them to my entities if I need to generate them manually?

EDIT.

Luke McGregor's post certainly brought me close. Yes it generates the views now. But the migrations don't work.

When trying to do a Update-Database statement the initial output is that there still are code changes.

I therefore executed the Add-Migration xxx Command and fired the Update-Database command again.

EDIT 2:

Resolving a few differences between my Code-first code and the view's SQL code solved this issue!


回答1:


You will need to create a manual migration with some raw SQL in it eg something along the lines of the below

public partial class MyMigration: DbMigration 
{ 
    public override void Up() 
    { 
        Sql("CREATE VIEW......"); 
    } 
}


来源:https://stackoverflow.com/questions/22964839/generating-a-sql-view-from-ef-6-1-code-first

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!