加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

通过F#和Npgsql在Postgresql中调用存储过程

发布时间:2020-12-13 16:08:45 所属栏目:百科 来源:网络整理
导读:我试图使用Npgsql类型提供程序从F#调用 postgresql中的存储过程. 目前,我连接到数据库如下: open Systemopen System.Dataopen System.Data.Entityopen System.Data.Linqopen Microsoft.FSharp.Data.TypeProvidersopen Microsoft.FSharp.Linqopen Npgsqlopen
我试图使用Npgsql类型提供程序从F#调用 postgresql中的存储过程.

目前,我连接到数据库如下:

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()

但是,我只看到db类型上的表,而不是任何存储过程.有没有办法通过类型提供程序以静态类型的方式使用存储过程,而不是只调用原始查询字符串?

解决方法

我知道这个问题是在不久前提出的,但我想我会添加一个对 SqlProvider的引用.这最近支持PostgreSQL添加到它,它包括对SPROCS的支持.

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

 [<Literal>]
 let resolutionFolder = @"D:DownloadsNpgsql-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
     ]

解析文件夹指向NPGSQL .NET程序集的位置.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读