c# - LINQPad: How to use SQLite integer primary key automatic assignment -


in sqlite:

if table contains column of type integer primary key, column becomes alias rowid.

when new row inserted sqlite table, rowid can either specified part of insert statement or can assigned automatically database engine.

if no rowid specified on insert, or if specified rowid has value of null, appropriate rowid created automatically.

i created table in sqlite integer primary key, , opened file in linqpad. i'm trying insert new row table via c#:

var episode = new rateableitem() {     sourceid = "tal",     edition = episodenum.tostring(),     name = episodename,     consumed = false };  rateableitems.insertonsubmit(episode); submitchanges(); 

in above example, haven't specified pimary key. fails because linqpad has mapped primary key non-nullable int, generated sql inserts 0 primary key, fails because row pk 0 exists.

is there way configure linqpad sqlite passes null pk, allowing sqlite automatically assign pk value?

thanks sample database @sgmoore posted in comments, able find declaring table primary key autoincrement solves issue.

create table rateableitem (   rateableitemid integer primary key autoincrement,   sourceid nvarchar(32) not null,   name nvarchar(255),   edition nvarchar(16),   consumed boolean not null ); 

when added autoincrement table definition, able create new object without specifying key. linqpad's schema explorer doesn't show difference between primay key autoincrement versus without, script compiles , sqlite assigns value on submitchanges().

there differences in primary key behavior autoincrement. fortunately these fine in scenario.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -