3

I'm very new to .Net and F#, so please keep that in mind....

I'm trying to connect to a PostgreSQL with F#, using the Npgsql EF provider. There have been a few posts about the same thing, but none of them actually offer a solution. The only one that I saw that apparently was able to make this work is the person in this post: Calling a stored procedure in Postgresql through F# and Npgsql

Unfortunately, he did provide details of the config. (If you're reading this, please post an answer! Thanks!)

Here's my setup:

In my App.config I have:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
    <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="4.0.0.0" newVersion="4.3.0.0" />
    <bindingRedirect oldVersion="2.3.5.0" newVersion="4.3.0.0" />
    <bindingRedirect oldVersion="2.0.0.0" newVersion="4.3.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.data>
    <DbProviderFactories>
      <add name="Npgsql Data Provider"
            invariant="Npgsql"
            description="Data Provider for PostgreSQL"
            type="Npgsql.NpgsqlFactory, Npgsql" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="MyDBContext"
         connectionString="Server=******;Database=mydb;User Id=uid;Password=passwd;"
         providerName="Npgsql" />
  </connectionStrings>
</configuration>

And this is what the code looks like:

open System.Data.Linq
open System.Data.Entity
open Microsoft.FSharp.Data.TypeProviders
open Npgsql
open NpgsqlTypes

type internal entityConnection = SqlEntityConnection<ConnectionStringName="MyDBContext">

let context = entityConnection.getDataContext();                                                                                    

This doesn't work or compile.

Any help would be greatly appreciated. If there's another way to do this (other than with Npgsql) I'm open to that as well.

Thanks!

4

0 回答 0