'How to get only specific tables to create models from database with Entity Framework Core in C#

I'm using Scaffold-DbContext to create models from an existing database, but it auto pluralizes the table names and I don't want that. It also gets all the tables but I need only a couple of them.

Is there a way to disable pluralization and select only some specific tables with that command?



Solution 1:[1]

Use

Scaffold-DbContext "[connection string here from database properties]" Microsoft.EntityFrameworkCore.SqlServer -OutputDir [path where your context should be created] -Tables ["tablename1","tablename2"] -NoPluralize

You can read this documentation for more information but this should get the job done.

Solution 2:[2]

If you have a look at the official documentation - you'd see:

Scaffold-DbContext

Parameters

...

  • Tables <String[]> - The tables to generate entity types for. If this parameter is omitted, all tables are included.

...

  • NoPluralize - Don't use the pluralizer. Added in EF Core 5.0.

So yes - both of your requests can be handled with parameters to Scaffold-DbContext - just consult the docs!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bani
Solution 2 marc_s