Can EFCore Scaffold-DbContext generate custom Model names?

c# ef-core-3.0 ef-database-first entity-framework-core scaffolding

Question

I'm using EFCore 3.0 with Database-first approach and was wondering about how Model names are generated. First of all, I'm using -DataAnnotations and -Force switches and the command looks like that:

Scaffold-DbContext "data source=foo;initial catalog=bar;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework;Connection Timeout=300;Application Name=FooBar" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Entities/Bar -ContextDir DbContexts -Context BarContext -Tables "Cars", "Makes", "Types" -DataAnnotations -Force

Scaffold-DbContext creates C# models exactly with the sames as tables in the database. So It will create 3 classes: Cars.cs, Makes.cs and Types.cs.

My question is: can we customize these names? Can I generate class Auto.cs instead of Cars.cs??

This task looks very trival, because from the human perspective it is this algorithm:

  1. Run Scaffold-DbContext

  2. Refactor-rename Cars.cs class to Auto.cs

  3. Done. Final result:

    [Table("cars")]
    public partial class Auto
    {
        public Auto()
        {
        }
    
    }
    

So if the answer to my first question is "No". My follow up question is: Can we somehow automate it? It's really not a complicated task. If we change the command line to something like:

-Tables "Cars" as "Auto", "Makes" as "Make", "Types" as "Type

Is there a way to change/override Scaffold-DbContext command? Has anyone done that? Thanks!

1
0
11/21/2019 5:51:20 PM

Accepted Answer

1
11/21/2019 6:56:35 PM


Related Questions





Related

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