Home > Software design >  Single context type, multiple providers
Single context type, multiple providers

Time:10-18

How do I setup and configure Entity Framework Core to use a single DbContext class and manage migrations for multiple providers (SQL Server, Sqlite)?

I have in production, a .NET 6 Blazor WASM project hosted in an ASP.NET Web API using the standard architecture of C# projects (client, API, logic, data, and shared projects). DbContext is injected into the repository and then used in the logic layer. Once the request is complete, the service is disposed as well as the DbContext. All good and well.

I want to create a companioning desktop app (WinUi 3) that utilizes the same Logic and data layer, but using an SQLite data provider. I could use a new DbContext class that inherits from existing DbContext, but then repository doesn't know which DbContext to use.

enter image description here

Data.Migrations.csproj (project only used for migrations as shown Projects

  • Related