How to retrieve indentity column vaule after insert using LINQ

Posted by Hobey on Stack Overflow See other posts from Stack Overflow or by Hobey
Published on 2009-03-19T21:17:31Z Indexed on 2010/04/12 22:23 UTC
Read the original article Hit count: 236

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about linq-to-sql