Configuration + another Type Provider

Hi everybody,

I like to specify my db connection in a yaml config. So I followed

On their own they work pretty good. Together it does not compile.

E.g:

open FSharp.Data.Sql

open FSharp.Configuration

[<Literal>]
let configPath = __SOURCE_DIRECTORY__ + "/" + "config.yaml" 

type Config = YamlConfig<configPath>
let config = Config()
let db = config.DB

//[<Literal>]
let connStr = $"User ID={db.UserId}..."

[<Literal>]
let connStrLiteral = "User ID=..."

type HR = SqlDataProvider<
            Common.DatabaseProviderTypes.POSTGRESQL, connStr,
            ResolutionPath = resolutionPath>

connStrLiteral works but it is hard-coded. With connStr I get

This is not a valid constant expression or custom attribute valueF# Compiler267

Do type providers not work in conjunction? Does somebody know a workaround?

Thank you!

I figured a solution would be having a compile connection string which must be hard-coded and a runtime connection string which can be provided by the YamlConfig.

E.g.

[<Literal>]
let configPath = __SOURCE_DIRECTORY__ + "/config.yaml" 

[<Literal>]
let resolutionPath = "temp"

type Config = YamlConfig<configPath>
let config = Config()
let db = config.DB

type HR = SqlDataProvider<Common.DatabaseProviderTypes.POSTGRESQL, Env.DB.connStr, ResolutionPath = resolutionPath>

[<EntryPoint>]
let main argv =
    let runtimeConnectionString = db.RuntimeConnectionString
    let ctx = HR.GetDataContext runtimeConnectionString