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# ?
views:
3283answers:
2
+5
A:
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);
James Curran
2008-11-06 14:33:47
There's a typo on line 3, it should read InsertOnSubmit(record)
Jonathan S.
2008-11-06 14:39:14
Thanks... "Fastest gun in the west" problem strike again....
James Curran
2008-11-06 14:44:15
A:
Any field with AutoGeneratedValue=true will be filled in after that record is submitted to the database by dc.SubmitChanges()
GeekyMonkey
2008-11-06 14:52:51