Insert row with existing autoincrement ID value

I’m doing something to migrate data (the MySQL migration tool crashes…long story…anyway) so I’m just using the ServiceStack models and ORMLite to read from one database and write to the other.

But inserting an object with an autoincrement non-zero Id value is being ignored, and instead creates a row with a new auto increment value. It seems AutoIncrement attribute always forces that column to be ignored from the INSERT statement.

public class Thing
  public int Id {get; set;}

// creates a new row with Id = 1 (the next autoincrement value)
Db.Insert<Thing>(new Thing()); 

// creates a new row of Id = 2 not 100
Db.Insert<Thing>(new Thing { Id = 100 }); 

This looks to be by design and I can’t see a simple way to override the behaviour. Do you have any suggestions, other than overriding the Id columns of each model definition?

Is it something can can be enhanced?

If this is a one-off migration you can modify the metadata for the Primary Key using the runtime metadata API, e.g:

    .PrimaryKey.AutoIncrement = false;

If this is a long running program you’ll need to set it back manually to restore the AutoIncrement behavior.

Thanks, that’ll help.