简体   繁体   English

使用 ASP.NET 动态数据/LINQ to SQL,如何让两个表字段与同一个外键有关系?

[英]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 文章提供了以下有用的建议:

  • 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.单击确定。

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.

相关问题 如何使用外键关系将数据从视图返回到 asp.net 中的 controller? - How do you return data from a view to controller in asp.net using foreign key relationship? 如何使用asp.net Web表单将数据插入SQL Server表中,在该表单中我具有外键约束且Identity设置为true - How to insert data into a SQL Server table using asp.net web form where I have foreign key constraint and Identity set to true Asp.Net,动态数据网站,外键一对一关系,DropdownList,如何自定义? - Asp.Net, Dynamic Data Website, Foreign key One to One relationship, DropdownList, how to customise? 动态数据asp.net DropdownList中的外键关系,如何自定义? - Dynamic Data asp.net Foreign key relationship in DropdownList, how to customise? 如何使用 ASP.NET 的动态数据脚手架将表设为只读 - How do you make a table read-only using ASP.NET's dynamic data scaffolding ASP.net动态数据中的Linq to SQL表继承 - Linq to SQL table inheritance in ASP.net Dynamic Data ASP.NET Linq to sql多个外键到主键的不同表 - ASP.NET Linq to sql multiple foreign keys to primary key different table 在ASP.NET动态数据外键显示中组合多个字段 - Combining mulitple fields in ASP.NET Dynamic Data foreign key display 如何使用asp.net获取SQL Server外键中的数据? - How to get data in a SQL Server foreign key using asp.net? 如何使用asp.net实体框架在SQL外键中获取数据? - How to get data in an sql foreign key using asp.net entity framework?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM