C# – LINQ to SQL Association – “Properties do not have matching types”

asp.netcdynamic-datalinq-to-sql

I am trying to link two fields of a given table to the same field in another table.
I have done this before so I can't work out what is wrong this time.

Anyway:

Table1
- Id (Primary)
- FK-Table2a (Nullable, foreign key relationship in DB to Table2.Id)
- FK-Table2b (Nullable, foreign key relationship in DB to Table2.Id)

Table2
- Id (Primary)

The association works for FK-Table2a but not FK-Table2b.
In fact, when I load into LINQ to SQL, it shows Table2.Id as associated to Table1.Id.
If I try and change this, or add a new association for FK-Table2b to Table2.Id it says: "Properties do not have matching types".

This also works in other projects – maybe I should just copy over the .dbml?

Any ideas?

Best Answer

I see this problem when I try to create one-to-one relationships where one side of the relationship is nullable (so really, one-to-zero/one). LINQ-to-SQL doesn't seem to support this so it appears we are forced to a plural relationship and a collection that will contain zero or one items. Annoying.