5
votes

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
You don't have a .EDMX file with a schema of table in it ? - Antoine Pelletier
@AntoinePelletier, EF.Core doesn't use edmx files. - Charles

3 Answers

4
votes

No, it is not supported, currently in the Backlog: https://github.com/aspnet/EntityFrameworkCore/issues/1679

5
votes

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.

1
votes

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