F#将SQLProvider与Postgres连接 [英] F# Connect SQLProvider with Postgres
问题描述
我是F#和.Net世界的初学者,我正在尝试使此F#脚本起作用:
I'm a beginner in both F# and the .Net world, I'm trying to make this F# script work:
#r "./packages/SQLProvider/lib/netstandard2.0/FSharp.Data.SqlProvider.dll"
#r "./packages/SQLProvider/lib/netstandard2.0/netstandard.dll"
#r "./packages/Npgsql/lib/netstandard2.0/Npgsql.dll"
open FSharp.Data.Sql
open Npgsql
let [<Literal>] ConnString =
"Host=localhost;" +
"Port=5431;" +
"Database=suavetododb;" +
"Username=postgres;" +
"Password=postgres"
let [<Literal>] DbVendor = Common.DatabaseProviderTypes.POSTGRESQL
let [<Literal>] ResPath = @"./packages/Npgsql/lib/netstandard2.0"
type Sql =
SqlDataProvider<
DbVendor,
ConnString,
"",
ResPath,
1000,
true>
这是我得到的错误:
错误FS3033:类型提供程序'FSharp.Data.Sql.SqlTypeProvider'报告错误:由于以下原因,无法解析字段标记0x04000523:无法加载字段'Npgsql.NpgsqlConnection + d__28的类型: <> u__2'(7)由于:无法加载文件或程序集'System.Threading.Tasks.Extensions,版本= 4.1.0.0,区域性=中性,PublicKeyToken = cc7b13ffcd2ddd51'或其依赖项之一。程序集:System.Threading.Tasks.Extensions,版本= 4.1.0.0,文化=中性,PublicKeyToken = cc7b13ffcd2ddd51类型:成员:(null)签名:程序集:(my_filesystem)/API/packages/Npgsql/lib/netstandard2.0/ Npgsql.dll类型:d__28成员:(空)签名:
error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Could not resolve field token 0x04000523, due to: Could not load type of field 'Npgsql.NpgsqlConnection+d__28:<>u__2' (7) due to: Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. assembly:System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 type: member:(null) signature: assembly:(my_filesystem)/API/packages/Npgsql/lib/netstandard2.0/Npgsql.dll type:d__28 member:(null) signature:
这很奇怪,因为 Npgsql
实际上是导入的(因此最后一个 #r
实际上可行)。
Which is weird, since Npgsql
is actually imported (so the last #r
actually works).
数据库已启动通过docker:
The database is up via docker:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4704763ec2ba suave_rezoom_db:0.1 "docker-entrypoint.s…" 25 hours ago Up 2 hours 0.0.0.0:5431->5432/tcp todo_rezoom_1
此外,该项目是通过.Net Core 2.1.200生成的,并且在Linux上运行。
Also, the project was generated via the .Net Core 2.1.200 and is running on Linux.
推荐答案
这是因为类型提供者需要解决depen第三方驱动程序(在这种情况下为 Npgsql
)的操作,但不能执行,因为它无法访问完整的依赖树,如NuGet(或Paket)做。您需要将 System.Threading.Tasks.Extensions.dll
复制到 Npgsql.dll
所在的文件夹中(您的 ResPath
),以便类型提供程序可以解析该程序集。
This is because the type provider needs to resolve dependencies of the third-party driver (Npgsql
in this case), and it can't because it doesn't have access to the full dependency tree like NuGet (or Paket) does. You need to copy System.Threading.Tasks.Extensions.dll
to the same folder where Npgsql.dll
sits (your ResPath
) so that the type provider can resolve that assembly.
一旦执行此操作,就会发现您还需要复制 System.Runtime.CompilerServices.Unsafe
。
Once you do that, you'll find that you also need to copy System.Runtime.CompilerServices.Unsafe
.
这篇关于F#将SQLProvider与Postgres连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!