views:

135

answers:

0

Hi,

QUESTION: How do I work around Entity Framework error I'm getting "Only key members can be mapped as part of the EndProperty mapping". I'm running VS2010 with C# project and Sqlite.

Background:

  • I imported two tables into the EF designer Webfiles and Relationships
  • I created an Associations between them
  • As Webfile.ID maps to Relationships.Parent_Id I (a) added an entity key to Relationships.Parent_Id, and then (b) Removed entity key from Relationships.Id [noting this ID in the relationships column isn't really used, but rather the Parent_ID and Child_ID columns are]

When I compile however I still get the following error:

Error 41 Error 2009: The property 'ID' is not a key member of the EntityType. Only key members can be mapped as part of the EndProperty mapping. C:\Documents and Settings\Owner\My Documents\My Dropbox\source\Test_EF_Sqlite\Model1.edmx 119 15 Test_EF_Sqlite

So my question is how do I avoid the need for the Relationships table to have an entity fields on it's ID column, but rather use the existing Relationship.Parent_Id column as the association back to Webfile.Id.

The XML looks like:

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"&gt;
  <!-- EF Runtime content -->
  <edmx:Runtime>
    <!-- SSDL content -->
    <edmx:StorageModels>
    <Schema Namespace="Model1.Store" Alias="Self" Provider="System.Data.SQLite" ProviderManifestToken="ISO8601" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl"&gt;
        <EntityContainer Name="Model1StoreContainer">
          <EntitySet Name="RELATIONSHIPS" EntityType="Model1.Store.RELATIONSHIPS" store:Type="Tables" />
          <EntitySet Name="WEBFILES" EntityType="Model1.Store.WEBFILES" store:Type="Tables" />
        </EntityContainer>
        <EntityType Name="RELATIONSHIPS">
          <Key>
            <PropertyRef Name="ID" />
          </Key>
          <Property Name="ID" Type="integer" Nullable="false" StoreGeneratedPattern="Identity" />
          <Property Name="PARENT_ID" Type="integer" Nullable="false" />
          <Property Name="CHILD_ID" Type="integer" Nullable="false" />
        </EntityType>
        <EntityType Name="WEBFILES">
          <Key>
            <PropertyRef Name="ID" />
          </Key>
          <Property Name="ID" Type="integer" Nullable="false" />
          <Property Name="PATH" Type="nvarchar" Nullable="false" MaxLength="50" />
         </EntityType>
      </Schema></edmx:StorageModels>
    <!-- CSDL content -->
    <edmx:ConceptualModels>
      <Schema xmlns="http://schemas.microsoft.com/ado/2006/04/edm" xmlns:cg="http://schemas.microsoft.com/ado/2006/04/codegeneration" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" Namespace="Model1" Alias="Self" >
        <EntityContainer Name="Model1Container" >
          <EntitySet Name="RELATIONSHIPS" EntityType="Model1.RELATIONSHIP" />
          <EntitySet Name="WEBFILES" EntityType="Model1.WEBFILE" />
          <AssociationSet Name="RELATIONSHIPWEBFILE" Association="Model1.RELATIONSHIPWEBFILE">
            <End Role="RELATIONSHIP" EntitySet="RELATIONSHIPS" />
            <End Role="WEBFILE" EntitySet="WEBFILES" />
          </AssociationSet>
        </EntityContainer>
        <EntityType Name="RELATIONSHIP">
          <Key>
            <PropertyRef Name="PARENT_ID" />
          </Key>
          <Property Type="Int64" Name="ID" Nullable="false" a:StoreGeneratedPattern="Identity" xmlns:a="http://schemas.microsoft.com/ado/2009/02/edm/annotation" />
          <Property Type="Int64" Name="PARENT_ID" Nullable="false" />
          <Property Type="Int64" Name="CHILD_ID" Nullable="false" />
          <NavigationProperty Name="WEBFILE" Relationship="Model1.RELATIONSHIPWEBFILE" FromRole="RELATIONSHIP" ToRole="WEBFILE" />
        </EntityType>
        <EntityType Name="WEBFILE">
          <Key>
            <PropertyRef Name="ID" />
          </Key>
          <Property Type="Int64" Name="ID" Nullable="false" />
          <Property Type="String" Name="PATH" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
          <NavigationProperty Name="RELATIONSHIPs" Relationship="Model1.RELATIONSHIPWEBFILE" FromRole="WEBFILE" ToRole="RELATIONSHIP" />
        </EntityType>
        <Association Name="RELATIONSHIPWEBFILE">
          <End Type="Model1.RELATIONSHIP" Role="RELATIONSHIP" Multiplicity="*" />
          <End Type="Model1.WEBFILE" Role="WEBFILE" Multiplicity="1" />
        </Association>
      </Schema>
    </edmx:ConceptualModels>
    <!-- C-S mapping content -->
    <edmx:Mappings>
    <Mapping Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">
  <EntityContainerMapping StorageEntityContainer="Model1StoreContainer" CdmEntityContainer="Model1Container">
    <EntitySetMapping Name="RELATIONSHIPS">
            <EntityTypeMapping TypeName="Model1.RELATIONSHIP">
              <MappingFragment StoreEntitySet="RELATIONSHIPS">
                <ScalarProperty Name="CHILD_ID" ColumnName="CHILD_ID" />
                <ScalarProperty Name="PARENT_ID" ColumnName="PARENT_ID" />
                <ScalarProperty Name="ID" ColumnName="ID" />
              </MappingFragment>
            </EntityTypeMapping>
          </EntitySetMapping>
          <EntitySetMapping Name="WEBFILES">
            <EntityTypeMapping TypeName="Model1.WEBFILE">
              <MappingFragment StoreEntitySet="WEBFILES">
                <ScalarProperty Name="PATH" ColumnName="PATH" />
                <ScalarProperty Name="ID" ColumnName="ID" />
              </MappingFragment>
            </EntityTypeMapping>
          </EntitySetMapping>
          <AssociationSetMapping Name="RELATIONSHIPWEBFILE" TypeName="Model1.RELATIONSHIPWEBFILE" StoreEntitySet="RELATIONSHIPS">
            <EndProperty Name="WEBFILE">
              <ScalarProperty Name="ID" ColumnName="ID" />
            </EndProperty>
            <EndProperty Name="RELATIONSHIP">
              <ScalarProperty Name="PARENT_ID" ColumnName="PARENT_ID" />
              <ScalarProperty Name="ID" ColumnName="PARENT_ID" />
            </EndProperty>
          </AssociationSetMapping>
        </EntityContainerMapping>
</Mapping></edmx:Mappings>
  </edmx:Runtime>
  <!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
  <edmx:Designer xmlns="http://schemas.microsoft.com/ado/2007/06/edmx"&gt;
    <edmx:Connection>
      <DesignerInfoPropertySet>
        <DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
      </DesignerInfoPropertySet>
    </edmx:Connection>
    <edmx:Options>
      <DesignerInfoPropertySet>
        <DesignerProperty Name="ValidateOnBuild" Value="true" />
        <DesignerProperty Name="EnablePluralization" Value="True" />
        <DesignerProperty Name="IncludeForeignKeysInModel" Value="False" />
      </DesignerInfoPropertySet>
    </edmx:Options>
    <!-- Diagram content (shape and connector positions) -->
    <edmx:Diagrams>
      <Diagram Name="Model1" >
        <EntityTypeShape EntityType="Model1.RELATIONSHIP" Width="1.5" PointX="3.125" PointY="1.375" Height="1.4279589843749996" />
        <EntityTypeShape EntityType="Model1.WEBFILE" Width="1.5" PointX="0.625" PointY="0.875" Height="2.9070849609374996" />
        <AssociationConnector Association="Model1.RELATIONSHIPWEBFILE">
          <ConnectorPoint PointX="3.125" PointY="2.1711531575520837" />
          <ConnectorPoint PointX="2.125" PointY="2.1711531575520837" />
        </AssociationConnector>
      </Diagram>
    </edmx:Diagrams>
  </edmx:Designer>

thanks