My data model contains two tables with composite primary keys and an associative table. Part of the composite primary key is common to tables.
SitePrivilege ------------- SiteId PrivilegeId UserSite -------- SiteId UserId UserSitePrivilege ----------------- UserId SiteId PrivilegeId
I created a SitePrivilege object and a UserSite object. I have mapped the many-to-many association between them in UserSitePrivilege.
<Association Name="UserSiteSitePrivilege"> <End Type="PrivilegeModel.UserSite" Multiplicity="*" Role="UserSite" /> <End Type="PrivilegeModel.SitePrivilege" Multiplicity="*" Role="SitePrivilege" /> </Association> ... <AssociationSetMapping Name="UserSiteSitePrivilege" TypeName="PrivilegeModel.UserSiteSitePrivilege" StoreEntitySet="UserSitePrivilege"> <EndProperty Name="SitePrivilege"> <ScalarProperty Name="PrivilegeId" ColumnName="PrivilegeId" /> <ScalarProperty Name="SiteId" ColumnName="SiteId" /> </EndProperty> <EndProperty Name="UserSite"> <ScalarProperty Name="SiteId" ColumnName="SiteId" /> <ScalarProperty Name="UserId" ColumnName="UserId" /> </EndProperty> </AssociationSetMapping>
The above code causes this error:
Each of the following columns in the UserSitePrivilege table maps to several conceptual side properties: UserSitePrivilege.SiteId maps to UserSiteSitePrivilegeSitePrivilege.SiteId, UserSiteSitePrivilege.UserSite.SiteId
So I added a reference constraint.
<Association Name="UserSiteSitePrivilege"> <End Type="PrivilegeModel.UserSite" Multiplicity="*" Role="UserSite" /> <End Type="PrivilegeModel.SitePrivilege" Multiplicity="*" Role="SitePrivilege" /> <ReferentialConstraint> <Principal Role="UserSite"> <PropertyRef Name="SiteId"/> </Principal> <Dependent Role="SitePrivilege"> <PropertyRef Name="SiteId"/> </Dependent> </ReferentialConstraint> </Association> ... <AssociationSetMapping Name="UserSiteSitePrivilege" TypeName="PrivilegeModel.UserSiteSitePrivilege" StoreEntitySet="UserSitePrivilege"> <EndProperty Name="SitePrivilege"> <ScalarProperty Name="PrivilegeId" ColumnName="PrivilegeId" /> <ScalarProperty Name="SiteId" ColumnName="SiteId" /> </EndProperty> <EndProperty Name="UserSite"> <ScalarProperty Name="SiteId" ColumnName="SiteId" /> <ScalarProperty Name="UserId" ColumnName="UserId" /> </EndProperty> </AssociationSetMapping>
Now it causes this error:
Properties provided by the Principal The UserSite role must be exactly identical to the EntityType PrivilegeModel.UserSite key referenced by the Primary role in the relationship is a restriction on the PrivilegeModel.UserSiteSitePrivilege relationship. Ensure that all key properties are specified in the Primary Role.
How to simulate this relationship?
source share