I have a stored procedure that updates a table using linq, eg: (this is just example code by way)
using (DataContext db = new DataContext())
{
d.sp_Insert_Client( textboxName.Text, textBoxSurname.Text);
}
What I would like to know is how to retrieve (if possible) newly generated primary key of the above inserted row, as I need this primary key as a foreign key to complete another insert.
You have to modify your stored procedure to return that value from database and then regenerate your Linq mapping to update that change in your ORM files. After that your
sp_Insert_Clientmethod will return an integer.The other way to do that is to add another parameter into the query and mark it as output one.
To get last inserted I’d inside your SP use
SCOPE_IDENTITY: http://msdn.microsoft.com/pl-pl/library/ms190315.aspx