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:
Run
Scaffold-DbContext
Refactor-rename
Cars.cs
class toAuto.cs
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!