Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 522
Jamie Babineau Avatar asked Jan 21 '16 16:01

Jamie Babineau


2 Answers

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.

like image 180
Oleg Avatar answered Oct 12 '22 02:10

Oleg


For EF Core 2.0, you should do:

Scaffold-DbContext -Connection "Connection String" -Povider "Microsoft.EntityFrameworkCore.SqlServer" -OutputDir Models -Tables "Table1", "Table2", "Table3", "TableN"
like image 28
Peinutz Avatar answered Oct 12 '22 01:10

Peinutz