I have two tables: address and contact, which are combined in contactID (in contact). Both of these tables have entities in my Entity data model (EF 4.0), and I do not want to modify them.
I want to create a new object that contains information from both objects.
What i have done so far:
In CSDL:
<EntityContainer...>
<EntitySet Name="AddressTest" EntityType="WebGearsModel.Test" />
<EntitySet Name="ContactTest" EntityType="WebGearsModel.Test" />
</EntityContainer>
<EntityType Name="Test">
<Key>
<PropertyRef Name="addressID" />
</Key>
<Property Type="Int32" Name="addressID" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<Property Type="Int32" Name="contactID" Nullable="false" />
<Property Type="String" Name="firstName" Nullable="false" MaxLength="30" FixedLength="false" Unicode="false" />
<Property Type="String" Name="emailAddress" Nullable="false" MaxLength="150" FixedLength="false" Unicode="false" />
</EntityType>
In my CS mapping:
<EntitySetMapping Name="AddressTest">
<EntityTypeMapping TypeName="WebGearsModel.Test">
<MappingFragment StoreEntitySet="Address">
<ScalarProperty Name="addressID" ColumnName="addressID" />
<ScalarProperty Name="contactID" ColumnName="contactID" />
<ScalarProperty Name="firstName" ColumnName="firstName" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<EntitySetMapping Name="ContactTest">
<EntityTypeMapping TypeName="WebGearsModel.Test">
<MappingFragment StoreEntitySet="Contact">
<ScalarProperty Name="contactID" ColumnName="contactID" />
<ScalarProperty Name="emailAddress" ColumnName="emailAddress" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
The error I am getting is:
The problem with displaying fragments, starting at line 150: you must specify a mapping for all key properties (ContactTest.addressID) of the EntitySet ContactTest.
How should I display the AddressID from a Contact object if it does not exist in this object? I suppose I need some kind of association, but I'm not sure how to do it ... Remember, I do not want to modify my existing Address and Contact objects.