如何讓Dapper.Rainbow插入到SQLite上的AutoIncrement表中?

c# dapper dapper-rainbow sqlite

我在SQLite上創建了一個示例表,其中Id列是自動遞增的。

CREATE TABLE "ESVLIntegration" ("Id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL  UNIQUE , "ProcessId" TEXT NOT NULL , "UserId" INTEGER NOT NULL , "Status" TEXT NOT NULL , "StartDate" DATETIME NOT NULL , "EndDate" DATETIME, "Operation" TEXT NOT NULL , "SNEquip" TEXT NOT NULL , "CardName" TEXT NOT NULL , "FilePath" TEXT NOT NULL , "Processed" BOOL NOT NULL )

但是當我第二次嘗試插入時,我收到以下錯誤:

由於約束違規而中止PRIMARY KEY必須是唯一的

這是我的代碼

public class ESVLIntegration
{
    public long Id { get; set; }
    public String ProcessId { get; set; }
    public long UserId { get; set; }
    public String Status { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
    public String Operation { get; set; }
    public String SNEquip { get; set; }
    public String CardName { get; set; }
    public String FilePath { get; set; }
    public Boolean Processed { get; set; }
}

public class Sample : Database<Sample>
{
    public Table<ESVLIntegration> ESVLIntegration { get; set; }
}

private void WriteParameters()
{
    "Writing sample parameters to SQLite DB".LogDebug();
    var pars = new ESVLIntegration();
    pars.ProcessId = Guid.NewGuid().ToString();
    pars.CardName = "gpp3";
    pars.StartDate = DateTime.Now;
    pars.Status = "Start";
    pars.Operation = VerifyStatus;
    pars.SNEquip = "12345";
    pars.FilePath = @"C:\Folder\FilePath";
    pars.Processed = false;
    using (var conn = new SQLiteConnection(connStr))
    {
       conn.Open();
       var db = Sample.Init(conn, 2);
       db.ESVLIntegration.Insert(pars);
    }
}

關於我在這裡做錯了什麼的想法?

編輯

SQlite上的INTEGER列的類型為int64(long)

一般承認的答案

從SQLite FAQ我發現:

有了這個表,聲明

INSERT INTO t1 VALUES(NULL,123);

在邏輯上等同於說:

INSERT INTO t1 VALUES((SELECT max(a)FROM t1)+1,123);

所以我只是將我的類ID改為可以為空

public class ESVLIntegration
{
    public long? Id { get; set; }
    public String ProcessId { get; set; }
    public long UserId { get; set; }
    public String Status { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
    public String Operation { get; set; }
    public String SNEquip { get; set; }
    public String CardName { get; set; }
    public String FilePath { get; set; }
    public Boolean Processed { get; set; }
}

現在它很棒!



許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因