EF inheritance / base class question
I am using entity framework and ria services. I am having a problem with mappings and inheritance. I have a (existing) table with 100+ columns, call it tblFacility, and I have it pulled into the EF designer. I want to use as little bandwidth as possible, and I only need two of the columns in most cases, an ID and a Description. So I added another entity, Facility and mapped it to tblFacility and mapped the two columns as well and set the key it ID. I then set the base class of the entity tblFacility to Facility.
My error is Error 3032: Problem in mapping fragments starting lines .... Entity Types dbModel.tblFaclity, dbModel.Facility are being mapped to the same rows in table tblMembers. Mapping conditions can be used to distinguish the rows that these types are mapped to.
The designer has Facility with two fields (one key/ID, one Description), and tblFacility is missing the two columns I just mentioned, which looks right. The edmx file looks like this where i am getting the error
<EntitySetMapping Name="Facilities">
<EntityTypeMapping TypeName="IsTypeOf(dbModel.Facility)">
<MappingFragment StoreEntitySet="tblFacility">
<ScalarProperty Name="Number" ColumnName="intFaclNbr" />
<ScalarProperty Name="Name" ColumnName="vcFaclName" />
</MappingFragment>
</Entity开发者_如何学编程TypeMapping>
<EntityTypeMapping xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs" TypeName="HSCAMasterModel.tblMember">
<MappingFragment StoreEntitySet=" tblFacility">
<ScalarProperty Name="Number" ColumnName="intFaclNbr" /> <ScalarProperty Name="vcAddr1" ColumnName="vcAddr1" />
<!--...over 100 more columns, name is not one of them...-->
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
At this point my client only needs Facility and doesn't need tblFacility, but the domain service does does need the tblFacility class. I wanted to use this Facility base class as an IQueryable Is this making any sense or am I way off base with how I should be using EF? Thanks!!
You cannot use inheritance for that. Inheritance has strict rules. On of this rules say that each record in the database can be represented by only one entity type in your inheritance hierarchy. So you cannot use inheritance to control how many columns of given record can be retrieved.
You need projection. You can either try to define projection directly in EDMX by using QueryView or you can check this blog post about using projection with domain services.
精彩评论