且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

c#-linq to sql-insert到同一表单的多个表中(在VIEW页面中)

更新时间:2023-01-31 19:40:30

为什么要使用LINQ?在任何情况下,答案必须是计算表之间的关系,并按照有意义的顺序插入数据。如果学生有地址ID,则需要先插入地址,以便分配该ID。如果学生只有一个地址,如果两个学生不能共享一个地址,那么这种设计就没有意义了。如果他们可以共享一个地址,你需要查询地址是否存在,然后创建它,如果它不存在。
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.