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?
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
.
For EF Core 2.0, you should do:
Scaffold-DbContext -Connection "Connection String" -Povider "Microsoft.EntityFrameworkCore.SqlServer" -OutputDir Models -Tables "Table1", "Table2", "Table3", "TableN"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With