D
Dev
Is it possible to have associations between subtypes?
Scenario:
I have 3 entity types as follows.
entity type B inherits from entity type A
entity type Y inherits from entity type X
I wish to have TPH for both A & B and X & Y hierachies.
DB schema is similar to the below.
TableFor_AB = {UniqueID_AB (PK), Discriminator_AB, ....}
TableFor_XY = {UniqueID_XY (PK), FieldFor_AB (FK), Discriminator_XY, .....}
in csdl association is defined as follows:
<Association Name ="Y_B">
<End Role ="B" Multiplicity ="1" Type ="Self.B"></End>
<End Role ="Y" Multiplicity ="*" Type ="Self.Y"></End>
</Association>
in SSDL association is defined as follows:
<Association Name ="FK_Y_B">
<End Role ="B" Type ="Self.TableFor_AB" Multiplicity ="0..1"></End>
<End Role ="Y" Type ="Self.TableFor_XY" Multiplicity ="*"></End>
<ReferentialConstraint >
<Principal Role ="B">
<PropertyRef Name ="UniqueID_AB"></PropertyRef>
</Principal>
<Dependent Role ="Y">
<PropertyRef Name ="FieldFor_AB"></PropertyRef>
</Dependent>
</ReferentialConstraint>
</Association>
Note: In the ssdl when defining schema for TableFor_XY, the FieldFor_AB has
been defined as nullable.
Reason is I want to be able to instantiate X without it participating in any
relationships with A or B.
(So I guess I have to keep FieldFor_AB as nullable)
in msl association is mapped as follows:
<AssociationSetMapping Name ="Y_B_Set" TypeName ="SomeNamespace.Y_B"
StoreEntitySet ="TableFor_XY">
<EndProperty Name ="B">
<ScalarProperty Name ="UniqueID_AB" ColumnName ="FieldFor_AB"/>
</EndProperty>
<EndProperty Name ="Y" >
<ScalarProperty Name ="UniqueID_XY" ColumnName ="UniqueID_XY"/>
</EndProperty>
<Condition ColumnName ="FieldFor_AB" IsNull ="false"/>
</AssociationSetMapping>
I'm fairly sure that the rest of the CSDL, SSDL, MSL are correct.
When I validate artificats without adding the association and related
navigation properties it doesnt report any errors and and I can run basic
queries against the EDM.
But when I validate artifacts after adding the association as shown above I
get the following error.
somepath\test.msl(14,6) : error 3019: Problem in Mapping Fragment(s)
starting at line(s) (14, 32):
Incorrect mapping of composite key columns.Foreign key constraint
'FK_Y_B' from table TabelFor_XY (FieldFor_AB) to table TableFor_AB
(UniqueID_AB):
Columns (FieldFor_AB) in table TableFor_XY are mapped to properties
(FieldFor_AB) in X_Set
and columns (UniqueID_AB) in table TabelFor_AB are mapped to properties
(UniqueID_AB) in A_Set.
However, the order of the columns through the mappings is not preserved.
Can somebody tell me whats wrong with above csdl,ssdl & msl fragements?
Thanks guys,
Dev
Scenario:
I have 3 entity types as follows.
entity type B inherits from entity type A
entity type Y inherits from entity type X
I wish to have TPH for both A & B and X & Y hierachies.
DB schema is similar to the below.
TableFor_AB = {UniqueID_AB (PK), Discriminator_AB, ....}
TableFor_XY = {UniqueID_XY (PK), FieldFor_AB (FK), Discriminator_XY, .....}
in csdl association is defined as follows:
<Association Name ="Y_B">
<End Role ="B" Multiplicity ="1" Type ="Self.B"></End>
<End Role ="Y" Multiplicity ="*" Type ="Self.Y"></End>
</Association>
in SSDL association is defined as follows:
<Association Name ="FK_Y_B">
<End Role ="B" Type ="Self.TableFor_AB" Multiplicity ="0..1"></End>
<End Role ="Y" Type ="Self.TableFor_XY" Multiplicity ="*"></End>
<ReferentialConstraint >
<Principal Role ="B">
<PropertyRef Name ="UniqueID_AB"></PropertyRef>
</Principal>
<Dependent Role ="Y">
<PropertyRef Name ="FieldFor_AB"></PropertyRef>
</Dependent>
</ReferentialConstraint>
</Association>
Note: In the ssdl when defining schema for TableFor_XY, the FieldFor_AB has
been defined as nullable.
Reason is I want to be able to instantiate X without it participating in any
relationships with A or B.
(So I guess I have to keep FieldFor_AB as nullable)
in msl association is mapped as follows:
<AssociationSetMapping Name ="Y_B_Set" TypeName ="SomeNamespace.Y_B"
StoreEntitySet ="TableFor_XY">
<EndProperty Name ="B">
<ScalarProperty Name ="UniqueID_AB" ColumnName ="FieldFor_AB"/>
</EndProperty>
<EndProperty Name ="Y" >
<ScalarProperty Name ="UniqueID_XY" ColumnName ="UniqueID_XY"/>
</EndProperty>
<Condition ColumnName ="FieldFor_AB" IsNull ="false"/>
</AssociationSetMapping>
I'm fairly sure that the rest of the CSDL, SSDL, MSL are correct.
When I validate artificats without adding the association and related
navigation properties it doesnt report any errors and and I can run basic
queries against the EDM.
But when I validate artifacts after adding the association as shown above I
get the following error.
somepath\test.msl(14,6) : error 3019: Problem in Mapping Fragment(s)
starting at line(s) (14, 32):
Incorrect mapping of composite key columns.Foreign key constraint
'FK_Y_B' from table TabelFor_XY (FieldFor_AB) to table TableFor_AB
(UniqueID_AB):
Columns (FieldFor_AB) in table TableFor_XY are mapped to properties
(FieldFor_AB) in X_Set
and columns (UniqueID_AB) in table TabelFor_AB are mapped to properties
(UniqueID_AB) in A_Set.
However, the order of the columns through the mappings is not preserved.
Can somebody tell me whats wrong with above csdl,ssdl & msl fragements?
Thanks guys,
Dev