如何从 ABP 框架中的实体框架创建视图(SQL) [英] How to create View (SQL) from Entity Framework in ABP Framework

查看:43
本文介绍了如何从 ABP 框架中的实体框架创建视图(SQL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况是我需要从另一个数据库查询并在我的应用程序中显示结果.两个数据库都在同一台服务器上.我想出了一个在我的数据库中创建 SQL-View 的想法,该视图将查询其他数据库以获取我想要的值.但是我不太确定如何从 ABP 框架创建或映射 SQL-View?

My situation is that I need to query from another database and show the result in my application. Both databases are on the same server. I came up with an idea on creating SQL-View in my database which would query the other database for values that I want. But I am not quite sure on how I can create or map SQL-View from the ABP framework?

我正在使用完整的 .Net 框架和 Angular 模板.

I am using the full .Net framework with the Angular template.

推荐答案

EF 不直接支持创建视图.所以你可以试试下面的方法.

Creating View is not directly supported in EF. So you can try the below approach.

  • 使用 Add-Migration 创建一个空的迁移.
  • 在生成迁移的Up方法中编写您的Create View脚本并使用 context.Database.ExecuteSqlCommand 方法运行脚本.
  • 声明您的类并使用 Table,就像您为模型类所做的那样.
  • Create an empty Migration using Add-Migration.
  • Write you Create View script in Up method of generated migration and run the script using context.Database.ExecuteSqlCommand method.
  • Declare your class and use Table as you do for your model class.

[Table("YourViewName")]public class YourClassName{

}

  • 像这样忽略你的视图类modelBuilder.Ignore();OnModelCreating 方法中.
  • 在包管理器控制台中运行 Update-Database.
  • Ignore your view class like this modelBuilder.Ignore<yourClassName>(); in OnModelCreating method.
  • Run Update-Database in Package Manager Console.

这篇关于如何从 ABP 框架中的实体框架创建视图(SQL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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