What's the best way to write a LINQ query that inserts a record and then returns the primary key of that newly inserted record using C# ?
The primary key value will be in that property after the SubmitChanges().
MyTable record = new MyTable();
record.Name = "James Curran";
db.MyTable.InsertOnSubmit(record);
db.SubmitChanges();
Console.WriteLine("record inserted as ID : {0}", record.Id);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With