efcore / efcore.configurationmanager Goto Github PK
View Code? Open in Web Editor NEWExtends EF Core to resolve connection strings from App.config
License: MIT License
Extends EF Core to resolve connection strings from App.config
License: MIT License
This is currently blocked by dotnet/runtime#931. This is the error you see:
A named connection string was used, but the name 'MyConnection' was not found in the application's configuration.
You can work around this by renaming the .config file in the output directory (aka bin\Debug) to ef.dll.config
.
Currently, you'll have to manually add a call to UseConfigurationManager
after scaffolding the DbContext.
We'll need to add a new hook in EF Core to allow doing this in a provider-agnostic manner.
the project file (in part):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EntityFrameworkCore.ConfigurationManager" Version="1.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.9" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
</ItemGroup>
the app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<!-- adjust this connection string as needed for your environment -->
<add connectionString="Server=.\SQLEXPRESS;Database=NorthWind;Trusted_Connection=True;" name="conn"/>
</connectionStrings>
</configuration>
the C# code:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
optionsBuilder.UseConfigurationManager().UseSqlServer("name=conn");
}
the command line:
dotnet ef migrations add base
the error:
System.InvalidOperationException: A named connection string was used, but the name 'conn' was not found in the application's configuration. Note that named connection strings are only supported when using 'IConfiguration' and a service provider, such as in a typical ASP.NET Core application. See https://go.microsoft.com/fwlink/?linkid=850912 for more information.
at EntityFrameworkCore.ConfigurationManager.ConfigrationManagerConnectionStringResolver.ResolveConnectionString(String connectionString)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection..ctor(RelationalConnectionDependencies dependencies)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerConnection..ctor(RelationalConnectionDependencies dependencies)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
I guess I thought that your library would deal with this translation?
The code does run, so it does use the name properly at runtime. Just not at design time.
``
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.