Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL LINQ
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 11-Dec-12 12:34pm
mil1234308

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 428
1 Maciej Los 249
2 BillWoodruff 199
3 /\jmot 180
4 Suraj Sahoo | Coding Passion 150
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100