dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.63k stars 3.15k forks source link

Scaffold views into SQL definitions on the model #20940

Open mm-ryo opened 4 years ago

mm-ryo commented 4 years ago

Hi,

I just run the Scaffold-DbContext command to generate DBModels. and we also want DB Views to be included in the generated DB Context. but we found the codes are not correct. it should call the ToView method instead of ToTable. please check the below codes. thank a lot.

modelBuilder.Entity("VTest", b =>
{
    b.Property<int?>("TestId1").HasColumnType("integer");
    b.Property<string>("TestId2").HasColumnType("text");
    b.ToTable("V_Test","public");
});

Steps to reproduce

Run below command

Scaffold-DbContext "****" Npgsql.EntityFrameworkCore.PostgreSQL -OutputDir Models

Further technical details

EF Core version: 3.1.3 Database provider: Npgsql.EntityFrameworkCore.PostgreSQL 3.1.3 Target framework: .NET Core 3.1 Operating system: Win 10 IDE: Visual Studio 2019 16.5.4

roji commented 4 years ago

@robinNode EF Core doesn't currently support creating views in the database (see #14537 and #465), therefore it's not possible to scaffold views in a way that creates them as views.

roji commented 4 years ago

Seems like we don't have a specific issue for tracking scaffolding of views to SQL definitions on the model, once #14537 is done (in #827?)

ajcvickers commented 4 years ago

@roji I would add it to the list in #827 and use this issue to track the enhancement.

roji commented 4 years ago

@ajcvickers done