Entity Framework v.4 supports two kinds of associations: "Independent" and "Foreign Key". All associations in a DevForce model must be "Foreign Key Associations".
The Entity Framework v.4 supports two types of association, "Foreign Key Associations" and "Independent Associations".
"Independent" associations were the only type of association in version 1 of EF. "Independent" associations hide their foreign keys and they lack a "Referential Constraint" section in their XML definitions.
Here's an example:
XML | <Association Name="CustomerOrder"> <End Type="DomainModel.Customer" Role="Customer" Multiplicity="1" /> <End Type="DomainModel.Order" Role="Order" Multiplicity="*" /> </Association> |
DevForce cannot work with these key-less "Independent" associations. All associations must be the "Foreign Key" type that was introduced in EF version 4. "Foreign Key" associations expose their foreign keys and have a "Referential Constraint" section as seen in this EDMX fragment.
XML | <Association Name="FK_Order_Customer"> <End Type="DomainModel.Customer" Role="Customer" Multiplicity="0..1" /> <End Type="DomainModel.Order" Role="Order" Multiplicity="*" /> <ReferentialConstraint> <Principal Role="Customer"> <PropertyRef Name="CustomerID" /> </Principal> <Dependent Role="Order"> <PropertyRef Name="CustomerID" /> </Dependent> </ReferentialConstraint> <Association> |
When you first created your EDM with the EDM Wizard and chose the "Data First" modeling approach, you were required to check the CheckBox next to "Include foreign key columns".
"Include foreign key columns" is especially critical. If you uncheck the option by accident, the "Update Model from Database" wizard creates new associations as "Independent" associations. You have to fix that.
You must restore the "Foreign Key" option. You can turn it back on in the "Update Model from Database..." wizard while adding a new object to the model
Or you can add the option in XML by editing the EDMX.
XML | <Options> <DesignerInfoPropertySet> <DesignerProperty Name="ValidateOnBuild" Value="true" /> <DesignerProperty Name="EnablePluralization" Value="True" /> <DesignerProperty Name="IncludeForeignKeysInModel" Value="True" /> </DesignerInfoPropertySet> </Options> |
You have to manually fix all associations that you created before re-engaging "Foreign Key Associations" as discussed in the "Model First" topic.
You must convert all existing "Independent" association to a "Foreign Key" association by (a) adding the foreign key properties manually and (b) adding a "Referential Constraint".
Open the "Referential Constraint" dialog either by double-clicking the Association line in the diagram or pressing the button in the "Referential Constraint" property.
Then fill in the blanks as in this example: