Reputation: 2730
I have seen several related questions here on stack overflow, however none appear to have answers. I will pose the question and then include links to related SO questions I have found.
I have a Core domain library written in C# that leverages Entity Framework. As such, EF requires the dbcontext to pass a connection string to the base (dbcontext). In my case the connection string lives in the app.config (or web.config) depends on top level project of course and the name is "AnnotatorModel".
I need to instantiate the DBContext from within my F# script to test a few queries and analytics.
I have added this to the app.config in my F# project and tried a few of the answers on SO with no success. Does anybody know a good easy straight forward way to accomplish this?
Here is the code, realize it breaks on attempting to instantiate the dbcontext, AnnotatorModel.
let PredictBestEntities (number:int) (tokens:string seq) =
let db = new AnnotatorModel()
tokens
|> Seq.map ...etc etc
Thanks, ~David
Related questions:
Get and use connection string from App.config F# AppSettings provider
App.config and F# Interactive not working
Upvotes: 2
Views: 1192
Reputation: 233337
This is not what you're asking, but I'll add this answer anyway:
Add a constructor overload to AnnotatorModel
that enables you to pass a connection string. This will enable you to write:
let db = new AnnotatorModel("some connection string")
Relying exclusively on a connection string in app.config tightly couples a library to that single source of configuration. This isn't good library design. Not only are you having trouble with using it from FSI, but it also makes it difficult to change 'configuration values' at run-time, load them from a database instead of a file, etc.
Libraries shouldn't be coupled to app.config. Only applications should use app.config.
Upvotes: 5