scampercat

scampercat

  • NA
  • 189
  • 0

linq to sql obtain primary keey value

Aug 25 2012 1:42 AM
In a C# 2010 application that I am working on, I want to use linq to sql to update 2 tables in a sql server 2008 database.

I want to do the following:
create new Table1 object ;
InsertOnSubmit(tbl1)
**Table 1 will contain the primary key.
create new Table2 object;
table2 will contain a foreign key column that refers to primary key in
table1 object.
InsertOnSubmit(tbl2)
SubmitChanges()

Before and/or right after the submitchanges() event occurs, I would like to know what the value is for the primary key in table1 and the foreign key value is in table2. I would like to know what the table key value is so I can display this information on reports that will be generated right after the record(s) have been inserted into the database. Thus can you tell me how to determine what the primary key value is for table1 that also refers to the foreign key value in table 2?



Answers (1)