New to F#, so I'm still kind of getting used to "type inference". I am trying to use EntityFramework in F# and when I try to build the connection, I get the error that my connection string (that's read from the app.config) is "not a valid constant expression or custom attribute value". If I hard-code the connection string it's fine, just like you'd expect.
open FSharp.Configuration
type Settings = AppSettings<"app.config">
let ConnStr = Settings.ConnectionStrings.Model
type private Connection = SqlEntityConnection<ConnectionString=ConnStr, Pluralize = true>
what am I doing wrong? is there a different, "F# way", of doing this?
Answer: 1° Celsius is equivalent to 33.8° Fahrenheit.
In the Celsius scale there are 100 degrees between the freezing point and the boiling point of water compared to 180 degrees in the Fahrenheit scale. This means that 1 °C = 1.8 °F (check the section about temperature differences below).
Answer: 50° Celsius is equal to 122° Fahrenheit.
SqlEntityConnection
is a Type Provider. Type Providers work at compile time (think of them as compiler plugins; or if you're into Lisp, think of them as a poor man's macros). Therefore, all Type Provider arguments need to be known at compile time.
Now, ask the question: is ConnStr
known at compile time?
No, of course it isn't, because you want to lift it from your config file.
The way you're supposed to work with this is:
Connection.GetDataContext
, give it the runtime connection string as argument. This will tell it to connect to whatever database is actually specified in your config, not the one you hard coded at compile time.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With