Reputation: 189
I want to generate entities and mappings in separate layers.
I try to use the following command in the package manager console to generate entities:
scaffold-DbContext "Data Source=.;Initial Catalog=MyDb;Persist Security Info=True;User ID=my;Password=123" Microsoft.EntityFrameworkCore.SqlServer
-OutputDir DataAccess\Entities -f -Verbose -t My_tbl1, My_Payment, tbl1
In Entity Framework and database first approach all entities, mapping and context are generated in a layer. But this causes problems with the absence of a separation of concern.
Upvotes: 0
Views: 154
Reputation: 89316
If you want the Entity definitions and Mapping to be managed separately, then you also probably don't want them updated automatically. So you could just generate them once with scaffold-DbContext, and then manually split them and keep them updated manually with any database changes you want reflected in your project. Or rerun scaffold-DbContext in another project and cut-and-paste.
If you want to customize the scaffolding process, EF Core doesn't really have anything built-in, but there's some add-ons that will help. Entity Framework Core Scaffolding with Handlebars. And some hooks that you can use to customize the type generation yourself. Entity Framework Core Customize Scaffolding
Upvotes: 1