Skip to content

Latest commit

 

History

History
59 lines (43 loc) · 2.02 KB

README.md

File metadata and controls

59 lines (43 loc) · 2.02 KB

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 3.x
7.0 2.x
6.0 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