ErikEJ / EFCorePowerTools

Entity Framework Core Power Tools - reverse engineering, migrations and model visualization in Visual Studio & CLI
MIT License
2.17k stars 297 forks source link

[Feature] Generate read DbContext from command one. #2594

Open voroninp opened 3 hours ago

voroninp commented 3 hours ago

When doing DDD one usually encapsulates aggregate's state and exposes behavior via aggregate root. Domain Models are used in command/write flow where aggregate is usually fetched by id. No extensive querying capabilities are required for this flow. However, for read flow it's better to have plain DTOs with navigation properties for the convenience of building queries using includes and projections.

So, I need to generate the second query-oriented DbContext based on the model defined in write-oriented DbContext. It's like poor man's CQRS where on database level read model is equivalent to write model. Currently, this can be achieved by creating a database using migrations of write-oriented DbContext and then reverse engineering the database back. But I wish I could omit this intermediary step.

Effectively, I want to automate the flow shown in Milan's video https://www.youtube.com/watch?v=iKDITShiZy4

ErikEJ commented 2 hours ago

Phew. This is NOT what EF Core Power Tools were designed for 😅

Despite being asked when creating the issue you are not giving any details about EF Core version or provider.. so I am guessing!

Would something like this work?

voroninp commented 2 hours ago

Yes, this can do the trick =) I'll try, thanks.

details about EF Core version or provider

Hm... will different models be generated based on provider?

ErikEJ commented 2 hours ago

.dacpac is only available for SQL Server/Azure SQL

For item 1 you can use the EF Core CLI

For item 2 you can use sqlpackage

For item 3 you can use EF Core Power Tools CLI

voroninp commented 2 hours ago

Ah, we use Postgres

ErikEJ commented 1 hour ago

That's exactly why this information matters. In that case you need to use the create script to publish the schema to a database