问题描述
我是 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, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"或其依赖项之一.程序集:System.Threading.Tasks.Extensions,版本=4.1.0.0,文化=中性,PublicKeyToken=cc7b13ffcd2ddd51 类型:成员:(空)签名:程序集:(my_filesystem)/API/packages/Npgsql/lib/netstandard2.0/npgsql.dll 类型:d__28 成员:(空)签名:
这很奇怪,因为 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.
推荐答案
这是因为类型提供者需要解析第三方驱动的依赖(本例中为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# 使用 Postgres 连接 SQLProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!