Entity Framework Core 2.0 Scaffold view from existing database

Viewed 13879

Is it possible to scaffold view from existing database in Entity Framework Core 2.0?

Something like command below:

Scaffold-DbContext "Server=xxx;Database=xxx; User Id=xxx; Password=xxx;"  
                   Microsoft.EntityFrameworkCore.SqlServer        
                   -OutputDir Models -Context TestStare 
                   -Tables Osebe -Views View1 -Force
3 Answers

From EF Core 3.0 it is possible to scaffold views and keyless entities Excerpt from Docs

Query types, which represent data that can be read from the database but not updated, have been renamed to keyless entity types. As they are an excellent fit for mapping database views in most scenarios, EF Core now automatically creates keyless entity types when reverse engineering database views.

You not need to write -Views... just add the names of views to tables list...

Scaffold-DbContext "Server=xxx;Database=xxx; User Id=xxx; Password=xxx;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Context TestStare -Tables Osebe, View1 -Force
Related