Matt Mitchell
Matt Mitchell

Reputation: 41853

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.

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:

Upvotes: 14

Views: 2276

Answers (1)

Matt Mitchell
Matt Mitchell

Reputation: 41853

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.

Upvotes: 5

Related Questions