Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i have a form in a view that collects student registration details. This form then should insert its fields to the student table and the address table for the sake of the question, as in reality it should insert into other tables. Therefore for this question imagine that i have the following 2 tables:

Student:
-------
id
name
surname
address_id

Address:
--------
id
house_name
house_address
locality
country
etc

How can i do this multiple insert with linq to sql so that when a user fills up the form from my view and this is submitted, the details related to the student table go into it and the address details go into the other table?

Thanks......
Posted

1 solution

Why do you have to use LINQ ? In any case, the answer has to be to work out the relationship between the tables, and insert the data in the order that makes sense. If a student has an address id, you need to insert the address first, so you have that id to assign. If a student only ever has one address, and if two students can't share an address, this design makes no sense. If they CAN share an address, you need to look up if the address exists, then create it if it doesn't.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900