Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to scaffold-dbcontext to different folders?

We can run the following command that will create the context and models in the project:

Scaffold-DbContext -Connection "Data Source=somedatasource.com;Initial Catalog=mydb;Integrated Security=False;User Id=user;Password=pass;MultipleActiveResultSets=True" -Provider Microsoft.EntityFrameworkCore.SqlServer -Tables PrdSalesRegion -Context SalesRegionContext

How do we specify different output folders for context and tables?

When I attempt to do this:

Scaffold-DbContext -Connection "Data Source=somedatasource.com;Initial Catalog=mydb;Integrated Security=False;User Id=user;Password=pass;MultipleActiveResultSets=True" -Provider Microsoft.EntityFrameworkCore.SqlServer -Tables Models/PrdSalesRegion -Context Context/SalesRegionContext

Note, that the only change is:

-Tables Models/PrdSalesRegion -Context Context/SalesRegionContext

Then I get this output:

The context class name passed in, Context/SalesRegionContext, is not a valid C# identifier.

How do we specify different output folders for context and tables?

like image 470
Alex Gordon Avatar asked Nov 06 '17 16:11

Alex Gordon


1 Answers

You can add the flag -o <DIR>. You could also use -f flag to override existing files while updating existing models with new fields.

The full command could be:

Scaffold-DbContext "Host=127.0.0.1;Database=dbname;Username=postgres;Password=test12345"Npgsql.EntityFrameworkCore.PostgreSQL -o Entities -f

Hope this helps

like image 52
kkost Avatar answered Oct 19 '22 18:10

kkost