Matt Dawdy
Matt Dawdy

Reputation: 19707

How can I make Entity Framework not create a class for some tables?

I have several tables in my DB that I do not want EntityFramework to create classes for. How can I tell EF to ignore certain tables?

I am not that familiar with configuring EF. The way we tell EF to look at our DB and create/change POCOs is by running a Nuget command line of "Scaffold-DbContext "a connection string" Microsoft.EntityFrameworkCore.SqlServer -DataAnnotations -Force -OutputDir Data"

Is there a way to tell EF to ignore specific tables?

Upvotes: 1

Views: 367

Answers (2)

Alan Macgowan
Alan Macgowan

Reputation: 481

You can specify which tables to include, using the -Tables parameter to specify the tables:

Scaffold-DbContext "connection-string" MySql.Data.EntityFrameworkCore -OutputDir dir -Tables table1,table2,table3  

Upvotes: 1

tnk479
tnk479

Reputation: 794

You can use the tables or schema switch to explicitly list which tables or schemas (include all tables within the schema) to reverse engineer.

https://learn.microsoft.com/en-us/ef/core/managing-schemas/scaffolding

Upvotes: 1

Related Questions