Entityframework.docs: Show an example for .Net Core other than ASP.Net Core

Created on 8 Oct 2018  Â·  10Comments  Â·  Source: dotnet/EntityFramework.Docs

There are examples for .Net Classic which is app.config happy, and ASP.Net core which talks about appsettings.json as a ASP.Net Core configuration system, but the case for .net Core console apps is plain absent (nor any pointer to a relevant place to look, for those migrating from the classic platforms...)


Document details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

area-getting-started closed-duplicate punted-for-2.2

Most helpful comment

All 10 comments

Ditto

@RowlandShaw @dyslexicanaboko @bigtfromaz there is an example that is a .NET Core console app at https://docs.microsoft.com/ef/core/get-started/netcore/new-db-sqlite. Wondering if your feedback is about the fact that you were not able to find it, that you would like to see examples of what to do with configuration (e.g. connection strings) in console apps, or something else.

I am looking for best practice when a .Net Standard library needs it's own runtime configuration, no matter where it is being used. In my case the business rules layer of the app is entirely encased in a std library. It is the only library that is to access the database. However each UI app that consumes the library needs to supply configuration values. app.config was a way to do that.

I was thinking more the what to do with the configuration, having come from EF6 that happily goes looking for the DefaultConnection in the app.config's configuration settings without having to think about it

@bigtfromaz - I think best practice would be to pass in any needed configuration as parameters and not rely on app.config/appsettings.json.

@divega it seems that a small sample for a .NET Core console application with a Microsoft.Extensions.Configuration could make sense, as well as a small note on why hard-coding the connection string is unadvisable. Note also #1344 which seems to be a dup of this.

There seem to be other requests on the same page for other types of connection strings (e.g. non-LocalDB, Azure...). As brief section pointing users to the right pages could help.

@roji from what I am reading in the comments from @bigtfromaz and @RowlandShaw, this issue was motivated by how the new configuration system doesn’t have a global static entry point that you can access from everywhere, but you rather need to pass around an IConfiguration directly or via de DI container. I.e. the main scenario mentioned is how to flow the application’s connection string into a .NET Standard library.

This is a concern that has been raised before, and it is product of a conscious design trade off.

It is actually a bit orthogonal to EF Core, but a sample of how to flow the connection string using EF Core or Microsoft.Configuration.Extensions abstractions would probably help.

I agree that having a page linking to the right way to configure for different data sources would help. The place for this kind of thing already exists in the providers page, but perhaps things can be improved. We currently link to the docs of the providers, but in many cases it is just a readme file that doesn't contain this kind of information.

Dupe of #481

Was this page helpful?
0 / 5 - 0 ratings

Related issues

qidydl picture qidydl  Â·  4Comments

davidliang2008 picture davidliang2008  Â·  4Comments

weitzhandler picture weitzhandler  Â·  4Comments

mjehle82 picture mjehle82  Â·  3Comments

jpeckham picture jpeckham  Â·  3Comments