首先从 EF 6.1 代码生成 SQL 视图

Generating a SQL view from EF 6.1 code first(首先从 EF 6.1 代码生成 SQL 视图)
本文介绍了首先从 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 的帖子确实让我很接近.是的,它现在生成视图.但是迁移不起作用.

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

当尝试执行 Update-Database 语句时,初始输出是仍有代码更改.

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

因此我执行了 Add-Migration xxx 命令并再次触发了 Update-Database 命令.

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

解决了我的代码优先代码和视图的 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 视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)