Jamie Babineau
Jamie Babineau

Reputation: 766

Database First but only a subset of the database

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?

Upvotes: 7

Views: 2560

Answers (2)

Peinutz
Peinutz

Reputation: 11

For EF Core 2.0, you should do:

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

Upvotes: 1

Oleg
Oleg

Reputation: 222017

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.

Upvotes: 8

Related Questions