After a lot of head scratching, I was finally able to accidentally duplicate a mapping issue reported to me by a reader of the Rough Cuts version of my book, Programming Entity Framework. Then after a lot more head scratching, I was able to discover the pattern and workaround for this problem, which has also surfaced a number of times in the forums.
The issue is when creating associations where one of the ends is a 0..1 (zero or one) and one of the entities involved is derived from another entity. This screenshot demonstrates the scenario.
The actual problem occurs when its time to map the association that has the 0..1 but the problem is behind the scenes and you would not know that it has occurred.
In the XML, the designer inserts a conditional mapping for the association:
<AssociationSetMapping Name="ActivityCustomer" TypeName="BAModel.ActivityCustomer" StoreEntitySet="Customers">
<EndProperty Name="Activity">
<ScalarProperty Name="ActivityID" ColumnName="PrimaryActivity" /></EndProperty>
<EndProperty Name="Customer">
<ScalarProperty Name="ContactID" ColumnName="ContactID" /></EndProperty>
<Condition ColumnName="PrimaryActivity" IsNull="false" />
</AssociationSetMapping>
In my scenario, however the condition was not being inserted and the model would not validate. Instead I was getting the frustrating Error 3034 telling me that two columns were mapped to the same row. It was only frustrating because I had gone around in circles with the error and could not figure out what the problem was. I even looked at the XML, but the condition mapping in a valid model had not caught my eye as the obvious difference between the two.
I was creating the association and defining the Activity end as 0..1 : *, then doing the mappings.
I discovered that if I first created the association as 1:*, then created the mappings, the condition was being inserted properly.
So this 0..1 was on the derived type was confusing the designer.
My solution, therefore is to create the association as 1:*, do the mappings and then go back to teh association and change the Activity end to 0..1. This does the trick .
The bug has been verified and logged.