Linq 中的一对多 Insert 语句
您好,我知道此类问题已经在 SO 上提出过。但我还没有得到满足。所以我发布了我自己的场景。 我的表单有 2-3 个文本框和一个复选框列表。有一对多关系,因此为了维护它,我有两个不同的表用于保存文本框值,另一个表保存上面的身份与多个复选框值。请参阅下图
我有 3 个表,其中两个用于 CRUD 操作。类别表用于绑定 checkboxlist 控件,而列表和类别列表映射是从上面显示的表单填充的表。
单击保存按钮时,前三个文本框值将转到 Listong 表,然后身份将配对从列表控件中选择复选框并保存到地图表。 这就是我需要的。
请帮我。
请注意:我使用的是Linq2Sql,没有用户定义的POCO,使用的实体类是由dbml本身生成的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,您需要创建一个新的Listing 对象和一个新的CategoryListingMap,其中listing = 您创建的Listing 对象,categoryid = 选择的id。保存 CategoryListingMap 时,数据库中也应该有一个新的列表条目。
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.