1

I'm trying to connect F# with an existing Postgresql database in a way that lets me take advantage of the database types during development (via Type Providers or Entity Framework, or a combination thereof).

The raw connection is straightforward to do using Npgsql. For example, the following code segment prints the contents of a Postgres table using F#.

open Npgsql
let connectionString = "(my postgres connection string)"
let getResultSet (connection:NpgsqlConnection) (queryString:string) =
 let command = new NpgsqlCommand(queryString, connection)
 let dataReader = command.ExecuteReader()
 seq {
 while dataReader.Read() do
 yield [for i in [0..dataReader.FieldCount-1] -> dataReader.[i]]
 }
let printResults = 
 let conn = new NpgsqlConnection(connectionString)
 conn.Open()
 try
 let resultSet = getResultSet conn "select * from myTable;"
 for r in resultSet do
 for d in r do
 printf "%s\t" (d.ToString())
 printfn ""
 finally
 conn.Close()

What's the best way to get a Type Provider for this set up or enable using Entity Framework with Postgresql on F#?

ildjarn
63.2k9 gold badges133 silver badges219 bronze badges
asked May 31, 2013 at 19:17

1 Answer 1

2

Since Npgsql is a ADO.NET provider you should be able to use the SqlEntityConnection type provider with an entity framework DBML file.

For more information see: http://msdn.microsoft.com/en-us/library/hh362322.aspx.

Priidu Neemre
3,0792 gold badges41 silver badges44 bronze badges
answered May 31, 2013 at 19:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.