如何从ABP框架中的实体框架创建视图(SQL) [英] How to create View (SQL) from Entity Framework in ABP Framework
问题描述
我的情况是我需要从另一个数据库查询并在我的应用程序中显示结果.两个数据库都在同一台服务器上.我想到了在数据库中创建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
方法中写您创建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 usingcontext.Database.ExecuteSqlCommand
method. - Declare your class and use
Table
as you do for your model class.
[Table("YourViewName")]
public class YourClassName
{
}
- 这样忽略您的视图类
OnModelCreating
方法中的modelBuilder.Ignore<yourClassName>();
. - 在程序包管理器控制台中运行
Update-Database
.
- Ignore your view class like this
modelBuilder.Ignore<yourClassName>();
inOnModelCreating
method. - Run
Update-Database
in Package Manager Console.
这篇关于如何从ABP框架中的实体框架创建视图(SQL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!