The DbContext¶
The EFCore Module will automatically register classes extending from DbContext
with the container as a scoped dependency. It will also configure them from
IConfiguration.
A valid DbContext for the EFCore Module could be:
Some key points here are:
- We are providing a name for a Connection String using the
   [DefaultSchemaName]attribute. This will configure ourDbContextto fetch a Connection String with that name fromIConfiguration. Read more on Connection Strings]
- We are extending from SuiteDbContext<TMyDbContext>. This is not required, but forces you to provide the right options, which are required for the Suite's Configuration to be applied to the DbContext
- We are injecting the DbContextOptions<TDbContext>that will contain the configuration for ourDbContextgenerated by the Suite. Read more on Configuring DbContext
Important
We recommend to always extend from SuiteDbContext<MyDbContext>. However, if
that's not possible, you can inject DbContextOptions<T> and use the
base(options) constructor of the DbContext class in order to integrate
with the Suite's Configuration.