entity-framework-coredbcontextscaffold

Entity Framework using wrong tablename for table class when execute Scaffold-DbContext command


I use this code to generate my project models:

Scaffold-DbContext "Server=.;User ID=*****;Password=*******;Database=*******;Trusted_Connection=True;Encrypt=False;" 
         Microsoft.EntityFrameworkCore.SqlServer 
         -OutputDir Models -force

After generating the classes, I see that EF generated PackageDatum class inside PackageData class - that is wrong!

public partial class PackageDatum
{
    public int Id { get; set; }
    public bool FloorOutOpen1 { get; set; }
}

My table name in the database is PackageData.

How can I fix this?


Solution

  • To disabe pluralization of the class names, use -NoPluralize switch on Scaffold-DbContext. See https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-5.0/breaking-changes#mitigations-18.