Skip to content

Extends EF Core to resolve connection strings from App.config

License

Notifications You must be signed in to change notification settings

efcore/EFCore.ConfigurationManager

Repository files navigation

EntityFrameworkCore.ConfigurationManager

build status latest version downloads license

Extends EF Core to resolve connection strings from App.config.

Installation

The latest stable version is available on NuGet.

dotnet add package EntityFrameworkCore.ConfigurationManager

Compatibility

The following table shows which version of this library to use with which version of EF Core.

EF Core Version to use
8.0 & 9.0 3.x
6.0 (Out of support) 2.x
3.1 (Out of support) 1.x

Usage

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

About

Extends EF Core to resolve connection strings from App.config

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages