2

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?

2
  • 3
    If code generati1on has already taken you to 90%, you might as well copy the couple of tables and their DB context mappings in a file and forget about the scaffold. Commented Apr 2, 2022 at 7:42
  • 2
    Have a look at EF Core Power Tools Commented Apr 2, 2022 at 8:01

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.