How to retrieve indentity column vaule after insert using LINQ
- by Hobey
Could any of you please show me how to complete the following tasks?
// Prepare object to be saved
// Note that MasterTable has MasterTableId as a Primary Key and it is an indentity column
MasterTable masterTable = new MasterTable();
masterTable.Column1 = "Column 1 Value";
masterTable.Column2 = 111;
// Instantiate DataContext
DataContext myDataContext = new DataContext("<<ConnectionStrin>>");
// Save the record
myDataContext.MasterTables.InsertOnSubmit(masterTable);
myDataContext.SubmitChanges();
// ?QUESTION?
// Now I need to retrieve the value of MasterTableId for the record just inserted above.
Kind Regards