mercredi 5 décembre 2018

SqLite Auto-increment for one its Composite Keys

SqLite Composite Keys

The following columns are set to auto-increment in SQL Server IDENTITY(1,1) and I wanted similar behavior on SqLite: Tenant.TenantID, Project.ProjectID, and Credits.CreditsID. Although there is AUTOINCREMENT in SqLite, and I have tried it, but it only works on tables with only 1 Primary Key. I have tried the following testing:

By the way, I used Microsoft.EntityFrameworkCore.Sqlite 2.1.4 for this testing

Explicitly assign value for these columns set to auto-increment:

  1. Tenant.TenantID

    a. -99 : remains -99 after saving

    b. 0 : becomes 1 after saving

    c. 99 : remains 99 after saving

  2. For Project.ProjectID & Credits.CreditsID

    a. -99 & 99 values remains the same after saving changes to DbContext. But I do not want to explicitly assign these values because there are bunch of test data from my DbContext.

    b. Assigning explicit value 0 throws this error: Microsoft.Data.Sqlite.SqliteException : SQLite Error 19: 'NOT NULL constraint failed: Credits.CreditsID'.

I'd really be grateful for someone who can help me out with this one. It's been days that this bothers me.

Aucun commentaire:

Enregistrer un commentaire