如何使用EF Core在Visual Studio中建模SQL Server数据库视图?

问题描述 投票:0回答:1

我在SQL Server中创建了一个视图。我想在Visual Studio中使用EF Core作为ORM并通过数据库优先的方法对该视图建模。如果有人可以告诉我有关解决方案的信息,我将不胜感激。

sql-server visual-studio ef-core-2.0 database-view
1个回答
0
投票

对于EF Core 2.1,使用属性来创建实体类以匹配您的视图字段,然后将其添加到数据库上下文中,例如:

public DbQuery<MyEntityType> ViewEntity{ get; set;}

然后可以像从DbSet中那样从上下文中查询它。

© www.soinside.com 2019 - 2024. All rights reserved.