Inheritance with POCO entities in Entity Framework 4
- by Juvaly
Hi All,
I have a Consumer class and a BillableConsumer : Consumer class. When trying to do any operation on my "Consumers" set, I get the error message "Object mapping could not be found for Type with identity Models.BillableConsumer.
From the CSDL:
<EntityType Name="BillableConsumer" BaseType="Models.Consumer">
<Property Type="String" Name="CardExpiratoin" Nullable="false" />
<Property Type="String" Name="CardNumber" Nullable="false" />
<Property Type="String" Name="City" Nullable="false" />
<Property Type="String" Name="Country" Nullable="false" />
<Property Type="String" Name="CVV" Nullable="false" />
<Property Type="String" Name="NameOnCard" Nullable="false" />
<Property Type="String" Name="PostalCode" Nullable="false" />
<Property Type="String" Name="State" />
<Property Type="String" Name="StreetAddress" Nullable="false" />
</EntityType>
From the C-S:
<EntitySetMapping Name="Consumers">
<EntityTypeMapping TypeName="IsTypeOf(Models.Consumer)">
<MappingFragment StoreEntitySet="consumer">
<ScalarProperty Name="LoginID" ColumnName="LoginID" />
<ScalarProperty Name="FirstName" ColumnName="FirstName" />
<ScalarProperty Name="LastName" ColumnName="LastName" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="IsTypeOf(Models.BillableConsumer)">
<MappingFragment StoreEntitySet="billinginformation">
<ScalarProperty Name="CardExpiratoin" ColumnName="CardExpiratoin" />
<ScalarProperty Name="CardNumber" ColumnName="CardNumber" />
<ScalarProperty Name="City" ColumnName="City" />
<ScalarProperty Name="Country" ColumnName="Country" />
<ScalarProperty Name="CVV" ColumnName="CVV" />
<ScalarProperty Name="LoginID" ColumnName="LoginID" />
<ScalarProperty Name="NameOnCard" ColumnName="NameOnCard" />
<ScalarProperty Name="PostalCode" ColumnName="PostalCode" />
<ScalarProperty Name="State" ColumnName="State" />
<ScalarProperty Name="StreetAddress" ColumnName="StreetAddress" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
Is this because I did not specifically add the BillableConsumer entity to the object set? How do I do that in a POCO scenario?
Thanks!
UPDATE: I decided to test whether or not POCOs generated with the T4 template would solve the problem and they did. The most annoying part is that when I restored my original classes from SVN to try and figure out how they are different - they worked as well!!
Not adding this as an answer because someone else might have an actual explanation...