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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

cc839ab · Nov 16, 2024

History

17 Commits
Nov 16, 2024
Nov 16, 2024
Dec 30, 2023
Oct 28, 2020
Oct 28, 2020
Oct 28, 2020
Oct 28, 2020
Oct 29, 2020
Nov 16, 2024
Oct 29, 2020

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