Extends EF Core to resolve connection strings from App.config.
The latest stable version is available on NuGet.
dotnet add package EntityFrameworkCore.ConfigurationManager
The following table shows which version of this library to use with which version of EF Core.
EF Core | Version to use |
---|---|
8.0 | 3.x |
7.0 | 2.x |
6.0 | 2.x |
3.1 (Out of support) | 1.x |
Enable the extension by calling UseConfigurationManager
inside OnConfiguring of your DbContext type. Use a special connection string containing the Name
keyword to resolve it from App.config.
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options
.UseConfigurationManager()
.UseSqlite("Name=MyConnection");
A corresponding App.config would look like this.
<configuration>
<connectionStrings>
<add name="MyConnection" connectionString="Data Source=My.db" />
</connectionStrings>
</configuration>
This extension also works at design time when scaffolding a DbContext.
Scaffold-DbContext Name=MyConnection Microsoft.EntityFrameworkCore.Sqlite
dotnet ef dbcontext scaffold Name=MyConnection Microsoft.EntityFrameworkCore.Sqlite