Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Linqpad to insert record with specified primary key?

So when I run the following, the role is inserted but the ID column is auto generated. How do I stop this from happening when using Linqpad?

Roles.InsertOnSubmit(new Role(){ID = 26, Name = "TheRole", Created = DateTime.Now, Updated = DateTime.Now});    
SubmitChanges(); 
like image 303
LivingOnACloud Avatar asked Aug 23 '13 15:08

LivingOnACloud


Video Answer


1 Answers

The ID column is set to AUTO INCREMENT in database, you can't override that from LINQ, you have to modify your database table schema to remove AUTO INCREMENT from table.

You can also enable IDENTITY_INSERT if you are using ADO.Net, see this question for related SQL details.

like image 133
Habib Avatar answered Oct 03 '22 14:10

Habib