[英]Using ASP.NET Dynamic Data / LINQ to SQL, how do you have two table fields have a relationship to the same foreign key?
I am using ASP.NET Dynamic Data for a project and I have a table that has two seperate fields that link to the same foreign key in a different table.我正在为一个项目使用 ASP.NET 动态数据,并且我有一个表,该表有两个单独的字段,这些字段链接到不同表中的相同外键。
This relationship works fine in SQL Server.这种关系在 SQL Server 中运行良好。
However, in the LINQ to SQL model in the ASP.NET Dynamic Data model, only the first field's relationship is reflected.但是,在 ASP.NET 动态数据模型中的 LINQ to SQL 模型中,仅反映了第一个字段的关系。 If I attempt to add the second relationship manually, it complains that it "Cannot create an association "ForeignTable_BaseTable". The same property is listed more than once: "Id"."
如果我尝试手动添加第二个关系,它会抱怨它“无法创建关联“ForeignTable_BaseTable”。同一属性被多次列出:“Id”。
This MSDN article gives such helpful advice as:这篇 MSDN 文章提供了以下有用的建议:
The solution is to delete and re-add BOTH tables to the LINQ to SQL diagram, not just the one you have added the second field and keys to.解决方案是将两个表删除并重新添加到 LINQ to SQL 图表中,而不仅仅是添加第二个字段和键的表。
Alternatively, it appears you can make two associations using the LINQ to SQL interface - just don't try and bundle them into a single association.或者,您似乎可以使用 LINQ to SQL 接口建立两个关联 - 只是不要尝试将它们捆绑到一个关联中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.