使用 ASP.NET 动态数据/LINQ to SQL,如何让两个表字段与同一个外键有关系?
我在一个项目中使用 ASP.NET 动态数据,并且有一个表,其中有两个单独的字段,这些字段链接到不同表中的相同外键。
这种关系在 SQL Server 中运行良好。
但是,在 ASP.NET 动态数据模型的 LINQ to SQL 模型中,仅反映第一个字段的关系。 如果我尝试手动添加第二个关系,它会抱怨“无法创建关联“ForeignTable_BaseTable”。同一属性多次列出:“Id”。”
这篇 MSDN 文章 提供了一些有用的建议,例如:
- 检查该消息并记下消息中指定的属性。
- 单击“确定”关闭消息框。
- 检查关联属性并删除重复的条目。
- 单击“确定”。
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.
This relationship works fine in SQL Server.
However, in the LINQ to SQL model in the ASP.NET Dynamic Data model, only the first field's relationship is reflected. 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"."
This MSDN article gives such helpful advice as:
- Examine the message and note the property specified in the message.
- Click OK to dismiss the message box.
- Inspect the Association Properties and remove the duplicate entries.
- Click OK.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案是删除两个表并将其重新添加到 LINQ to SQL 图表中,而不仅仅是添加了第二个字段和键的表。
或者,您似乎可以使用 LINQ to SQL 接口建立两个关联 - 只是不要尝试将它们捆绑到单个关联中。
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.
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.