How to get Dapper.Rainbow to insert into a table using AutoIncrement on SQLite?

I created a sample table in SQLite that has an identifier column that grows automatically.

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 )

But when I try to paste a second time, I get the following error:

Interruption due to violation of restrictions. PRIMARY KEY must be unique

This is my code.

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);
    }
}

Any ideas on what I'm doing wrong here?

EDIT

INTEGER columns on SQlite are of type int64 (long)

+5
source share
1 answer

From the SQLite FAQ, I found:

Statement in this table

INSERT INTO t1 VALUES (NULL, 123);

logically equivalent to the above:

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

So, I just changed my class id to zero

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; }
}

!

+5

All Articles