Database First but only a subset of the database

.net-core entity-framework-core

Question

I am creating an asp.net6 web application that will pull back transactional data from an existing database. Inside the database we have a lot of lookup tables that I don't have a need for. I am able to import the database with ef dbcontext scaffold but I get all the tables in the database. Is there a way to pick and choose the tables I want? I can delete all the lookup tables but if I ever have to update any of them and I use the ef dbcontext scaffold will it pull all the tables again?

Accepted Answer

Yes you can. I searched a long time for the solution of the problem in the past. The options of ef dbcontext scaffold are documented not good enough. The solution as the using -t parameter multiple times:

dnx ef dbcontext scaffold ... -t dbo.Users -t dbo.UserPosts

I described the usage of ef dbcontext scaffold more detailed in the answer. It includes the reference to the Design Meeting Note.

UPDATED: Starting with .NET Core RC2 one should use dotnet ef dbcontext scaffold instead of dnx ef dbcontext scaffold.


Popular Answer

For EF core 2.0 you shoud do :

Scaffold-DbContext -Connection "Connection String" -Povider "Microsoft.EntityFrameworkCore.SqlServer" -OutputDir Models -Tables "Table1", "Table2", "Table3", "TableN"


Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why