f# - Dapper F# - A Parameterless default 一个无参数的默认构

出于演示目的,我正在制作一个 Insert 函数,我想返回一个传入类型的变量。

我是初始查询的用户 Dapper.fsharp,然后我想运行原始 SQL 查询以获取最后插入的值。

所以我有这样的东西用于演示目的

let Insert<'a> asyncQuery =
    asyncQuery
        |> connection.InsertAsync<'a>
        |> RunSynchronously
        |> ignore
    (*This is a Dapper.fsharp query. Running this returns the number of rows inserted (int) *)

    let table = asyncQuery.Table (*This is a string*)
    let result = 
          connection.Query<'a>($"""Select * From {table} Where id = (select last_insert_id())""") (*Should return an IENumerable of type 'a*)
          |> EnumerableToArray
           
    result |> first

然后这就是所谓的喜欢

let newSession =
            insert {
                table "sessions"
                value newSession
            } |> Insert

其中 newSession 是 session 类型

module Session
type session = {id: int; session_id: string; clerk_json: string; clerk_id: int; expires: int}
(*This is also the structure of the SQL table exactly*)

我得到的错误是

"A parameterless default constructor or one matching signature (System.Int32 id, System.String session_id, System.Int32 clerk_id, System.String clerk_json, System.Int32 expires) is required for Session+session materialization"

这向我表明它没有从数据库中获得正确的类型签名,但列名和类型匹配,并且表中没有任何内容为空。

也许我忽略了一些简单的事情或误解了应该如何使用该库?

最佳答案

类型必须是 [<CLIMutable>] ...

关于f# - Dapper F# - A Parameterless default 一个无参数的默认构造函数或一个匹配的签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69868828/

相关文章:

java - 如何在 Java 中为 5x5 二维数组正确使用制表符空间?

python - 将多列的不同值组合成 Polars 中的一列

python - 仅当 Pandas 中的所有值均为 0 时,才将 0 替换为选定列的 NaN

reactjs - Next.js 应用程序是 SPA 还是单页应用程序?

sql - 在 exec 中声明变量会改进 SQL 查询计划吗?

.net-core - SSE 和 AVX 的 MoveMask 的目的是什么

regex - 如何验证用户输入中的 Perl 正则表达式?

python - 如何在 python 中删除表的某些行?

java - Spring Boot 服务层 : Unit or Integration tests

javascript - 遍历对象数组并获得新的对象数组