简体   繁体   中英

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?

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM