Interpolated strings in F#

entity-framework-core f# formattablestring sql

Question

I am trying to use the Entity Framework Core interpolated SQL query function in F# which requires a FormattableString. However to my surprise it doesn't function as I cannot find a way to convert a regular F# string to that type. I figured just doing what you do in C# would work but it doesn't. Here is the code I currently have:

let fromDbUser (u : Entity.User) = 
    {
        name = u.Name
        age = u.Age
        phone = u.Phone
    }

let mname = "Foo" 

let ctx = new Entity.DatabaseContext()
ctx.User.FromSqlInterpolated($"Select * FROM User Where name = {mname};") 
|> Seq.map(fromDbUser)
|> printfn "%A"

Running that block of code yields a compile error:

This token is reserved for future use

I have been trying to google around but I was unable to find any way to get this to work, any help would be most appreciated!

1
4
2/7/2020 9:24:06 PM

Popular Answer

F# doesn't have string interpolation.

There is an RFC for it that is approved-in-principal.

The error is because the $ symbol is reserved (for 6 years+ as of writing), and will probably be used for string interpolation when it is added.

5
2/7/2020 10:38:41 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow