Calling a stored procedure in Postgresql through F# and Npgsql

﹥>﹥吖頭↗ 提交于 2019-12-04 03:26:06

问题


I am trying to call a stored procedure in postgresql from F# using the Npgsql type provider.

Currently, I am connected to the database as follows:

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

type internal dbSchema = SqlEntityConnection<ConnectionString="**my connection string**", Provider="Npgsql">

let internal db = dbSchema.GetDataContext()

However, I only see the tables on the db type, not any of the stored procedures. Is there a way to use the stored procedures in a statically typed manner through the type provider, instead of just calling the raw query string?


回答1:


I know this question was asked along time ago, but I thought I would add a reference to the SqlProvider. This has recently had support for PostgreSQL added to it and it includes support for SPROCS.

 [<Literal>]
 let connStr = "User ID=postgres;Password=password;Host=POSTGRESQL;Port=9090;Database=hr;"

 [<Literal>]
 let resolutionFolder = @"D:\Downloads\Npgsql-2.1.3-net40\"

 type HR = SqlDataProvider<ConnectionString=connStr,DatabaseVendor=Common.DatabaseProviderTypes.POSTGRESQL, ResolutionPath = resolutionFolder>
 let ctx = HR.GetDataContext()

 ctx.Procedures.ADD_JOB_HISTORY(100, DateTime(1993, 1, 13), DateTime(1998, 7, 24), "IT_PROG", 60)


 //Support for sprocs that return ref cursors
 let employees =
     [
       for e in ctx.Functions.GET_EMPLOYEES().ReturnValue do
           yield e
     ]

Where the resolution folder points to the location of the NPGSQL .NET assemblies.




回答2:


From the look at you are seeing, it looks like this is not supported somewhere between npgsql, f#, and npgsqltypes. The chance of you getting a good answer here is very low because it would require someone with a strong understanding of this language, the architecture of it, and where exactly each piece of the puzzle relies. It might also require debugging to see what is going wrong.

The previous suggestions were:

  1. Since PostgreSQL doesn't really have stored procedures per se, F# might not recognize them, and

  2. npgsqltypes might be missing some important aspects on the mapping.

I would expect that npgsql would not be where I would start looking at this because, in theory, the type provider should be able to do the lookups itself.

So I would recommend getting on relevant email lists and asking about this assuming it to be a problem with your type provider. Anyone who knows enough to troubleshoot will probably be on those email lists.



来源:https://stackoverflow.com/questions/16907198/calling-a-stored-procedure-in-postgresql-through-f-and-npgsql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!