F# type providers to support statically typed access to input parameters and result set of sql statement in idiomatic F# way. Data modifications via statically typed tables.
I am getting following error when reading Geometry column from table.
System.InvalidOperationException: 'Expected column "geom" of type "System.Object" at position 6 (0-based indexing) but received column "geom" of type "NetTopologySuite.Geometries.Geometry".'
The column in database table is declared as
geom geometry(Point,4326),
Using Npgsql works correctly.
I have following set but it looks like the type provider is not respecting it.
// Learn more about F# at http://fsharp.org
open System
open Npgsql
NpgsqlConnection.GlobalTypeMapper.UseNetTopologySuite() |> ignore
open FSharp.Data.Npgsql
open System.Runtime.InteropServices
module DbConnection =
[<Literal>]
let ConnectionStringName = "ConnectionStringName"
let private IsWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
let private ConnectionStringSeparator = if IsWindows then ":" else "__"
let AppConnectionString = lazy Environment.GetEnvironmentVariable("ConnectionStrings" + ConnectionStringSeparator + ConnectionStringName)
type AppProvider = NpgsqlConnection<DbConnection.ConnectionStringName, ConfigType = ConfigType.Environment>
let openConnection() =
let con = new Npgsql.NpgsqlConnection(DbConnection.AppConnectionString.Value)
con.Open()
con.TypeMapper.UseNetTopologySuite() |> ignore
con
let testNpgsql() =
let conStr = @"mycon";
use con = new Npgsql.NpgsqlConnection(conStr)
con.Open()
use cmd = new Npgsql.NpgsqlCommand("select geom from addresses", con)
use reader = cmd.ExecuteReader()
reader.Read() |> ignore
printfn "%A" reader.[0]
let testTypeProvider() =
use con = openConnection()
use trn = con.BeginTransaction()
use cmd =
AppProvider.CreateCommand<"select * from addresses", XCtor = true>(con, trn)
let address = cmd.Execute() |> List.head
printfn "%A" (address.geom)
[<EntryPoint>]
let main argv =
//testNpgsql()
testTypeProvider()
0 // return an integer exit code
I am getting following error when reading Geometry column from table.
The column in database table is declared as
Using Npgsql works correctly.
I have following set but it looks like the type provider is not respecting it.
following is the test app code