How to map an existing view using EntityFramework Core? ef-code-first entity-framework-core


I know how to map table from tutorial

public DbSet<AccountEntity> Account { get; set; }
//..... OnModelCreating

Let's say there is an view in database named V_Account, how can I map to this view and use it as _context.V_Account?

4/1/2017 9:35:30 AM

Popular Answer

As far as I am concerned it's not possible yet to map to a view. See the "Critical O/RM features" on the EF Core Roadmap Docs on GitHub

Critical O/RM features

The things we think we need before we say EF Core is the recommended version of EF. Until we implement these features EF Core will be a valid option for many applications, especially on platforms such as UWP and .NET Core where EF6.x does not work, but for many applications the lack of these features will make EF6.x a better option.


  • Complex/value types are types that do not have a primary key and are used to represent a set of properties on an entity type.
  • Stored procedure mapping allows EF to use stored procedures to persist changes to the database (FromSql already provides good support for using a stored procedure to query).
  • View mapping allows EF to map to database views.

See the last point, which means that it's still on the roadmap. Since it's not yet in the Roadmap for EF Core 2.0 it's to be assumed that it won't come until a later version.

If you need such features you should fall back to using EF 6.x (but then unable to target .NET Core, just .NET Framework 4.x)

4/1/2017 9:34:51 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow