从EF 6.1代码首先生成SQL视图 [英] Generating a SQL view from EF 6.1 code first

查看:200
本文介绍了从EF 6.1代码首先生成SQL视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是改变了从数据库中我的应用程序的第一代码第一!什么部署有很大的改善!但现在我有以下问题。我生成我的代码,第一个模型从我的数据库,但生成的代码重新创建数据库之后,都喜欢表生成从我的数据库我的看法!

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?

编辑。

卢克麦格雷戈当然后给我带来接近。
是的,它现在生成的意见。但是,迁移不起作用。

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.

因此,我执行附加迁移XXX命令,再次打响了更新-database命令

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

编辑2:

解决我的代码,第一个代码和视图的SQL代码之间的一些分歧解决了这个问题!

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

推荐答案

您将需要它来创建一些原始的SQL手工迁移低于

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

这篇关于从EF 6.1代码首先生成SQL视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆