我正在使用C# (.NET 3.5)中的强类型数据集和ADO.NET。我想要向两个相关的1:n关系表中插入新行。
Attachments
表保存关系的主键部分,而LicenseAttachments
表保存外键部分。
AttachmentsDataSet.InvoiceRow invoice; // Set to a valid row, also referenced in InvoiceAttachments
AttachmentsDataSet.AttachmentsRow attachment;
attachment = attachmentsDataSet.Attachments.AddAttachmentsRow("Name", "Description");
attachmentsDataSet.InvoiceAttachments.AddInvoiceAttachmentsRow(invoice, attachment);
当我首次更新InvoicesAttachments
表时,我会从SQL服务器得到外键违规警告,因此我尝试先更新Attachments
表,这将创建行,但将删除InvoiceAttachments
表中的附件关联。为什么?
如何解决这个问题?