简体   繁体   中英

One to Many Insert statement in Linq

Hi I know this type of question is already asked on SO. But I havent get satisfied. So i am posting my own scenario. I have form with 2-3 textboxes and a checkedboxlist. There 1 to many relationship, so to maintain it i have two different tables on for holding the text box values and another holds the Identity of above with the multiple checkbox values. Refer the image below

在此处输入图片说明

I have 3 tables for that out of which two are used for CRUD operation. Category table is used for binding the checkedboxlist control whereas the Listing and CategoryListing Map are the tables populated from the form shown above. 在此处输入图片说明

When save button will clicked, First three textbox values will go to Listong table and the identity will then paired up with the selected checkbox from the list control and save to map table. This is what i need.

Please help me.

Pls Note : I am using Linq2Sql, there is no user defined POCO, the entity class used is generated by the dbml itself.

Basically you'll need to create a new Listing object and a new CategoryListingMap, which will have listing = the Listing object you created and categoryid = the id selected. On saving the CategoryListingMap, you should have a new Listing entry in db as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM