Search code examples
f#asp.net-core-mvcfsharp.data.sqlclient

Using Fsharp.Sql.DataClient via a referenced project in asp.net core


I am building an Asp.net Core (.NET Framework 4.6.2) project. I added a referenced F# project that uses FSharp.Sql.DataClient. When I call the F# code from the main project to retrieve data from the database I get this error:

Keyword not supported: 'name'

This worked perfectly in projects before Asp.net Core, so I am guessing this may have something to do with how the connection strings are defined in the appsettings.json file in the main project, opposed to a config file in previous versions, and in the config file within the referenced F# project. My sql code is defined like this:

type Select_AllTags =

    SqlCommandProvider<
            "
                select * from article.article_Tag
            ", Admin.connectionName, ConfigFile = Admin.configFile
        >

called later in the code like this:

Select_AllTags.Create(Admin.connectionString).Execute()

How can I make this work with Asp.net Core?


Solution

  • For what ever reason my initial code worked in previous DotNet Core apps, but now I must call the actual connection string when calling the code at run time. So here is the updated code:

    let connectionName = "ManagementDb"
    let configFile = "web.config"
    let runtimeConnectionString = Config.ConnectionStrings.ArticleManagementDb //Using FSharp.Configuration here to grab the connection string
    
    type Select_AllTags =
    
    SqlCommandProvider<
            "
                select * from article.article_Tag
            ", connectionName, ConfigFile = configFile
        >
    
    Select_AllTags.Create(runtimeConnectionString).Execute()