title: EntityFramework mappings - what is wrong with this mapping?
body: <p>I'm kind of stuck working out where I'm going wrong with the below entity framework mapping.  What I've done is:</p>
  
  <p>a) created a Sqlite database (see below, noting Sqlite doesn't allow FK constraints)
  b) created a blank Entity Data Mode &amp; then created the model from the database
  c) issue is then trying to add the Model association so it picks up and uses the "ProcessNameId" column I've created in the database in the USAGES table.  I've been trying to use the GUI Table Mapping pane to do this but it doesn't seem too intuitive.  </p>
  
  <p>Issue - I'm getting the following error:</p>
  
  <pre><code>Error 3 
  Error 3021: Problem in mapping fragments starting at line 85:
  Each of the following columns in table Usages is mapped to multiple conceptual side properties:
  
  Usages.ProcessNameId is mapped to &lt;ProcessNameUsage.ProcessName.Id,  ProcessNameUsage.Usage.Id&gt;
  Error   4
  Error 3025: Problem in mapping fragments starting at line 85:
  Must specify mapping for all key properties (Usages.Id) of table Usages.
  </code></pre>
  
  <p>Question - So the question is what changes to the XML do I need to make to have the association work correctly?</p>
  
  <p>SQL</p>
  
  <pre><code>CREATE TABLE "ProcessNames" (
      "Id" INTEGER PRIMARY KEY  AUTOINCREMENT NOT NULL , 
      "Name" VARCHAR NOT NULL  UNIQUE
  )
  
  CREATE TABLE "Usages" (
      "Id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , 
      "ProcessNameId" INTEGER NOT NULL , 
      "Amount" INTEGER NOT NULL , 
      "Datetime" DATETIME NOT NULL 
  )
  </code></pre>
  
  <p>Model Config</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx"&gt;
    &lt;!-- EF Runtime content --&gt;
    &lt;edmx:Runtime&gt;
      &lt;!-- SSDL content --&gt;
      &lt;edmx:StorageModels&gt;
      &lt;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/2009/02/edm/ssdl"&gt;
          &lt;EntityContainer Name="Model1StoreContainer"&gt;
            &lt;EntitySet Name="ProcessNames" EntityType="Model1.Store.ProcessNames" store:Type="Tables" /&gt;
            &lt;EntitySet Name="Usages" EntityType="Model1.Store.Usages" store:Type="Tables" /&gt;
          &lt;/EntityContainer&gt;
          &lt;EntityType Name="ProcessNames"&gt;
            &lt;Key&gt;
              &lt;PropertyRef Name="Id" /&gt;
            &lt;/Key&gt;
            &lt;Property Name="Id" Type="integer" Nullable="false" StoreGeneratedPattern="Identity" /&gt;
            &lt;Property Name="Name" Type="nvarchar" Nullable="false" /&gt;
          &lt;/EntityType&gt;
          &lt;EntityType Name="Usages"&gt;
            &lt;Key&gt;
              &lt;PropertyRef Name="Id" /&gt;
            &lt;/Key&gt;
            &lt;Property Name="Id" Type="integer" Nullable="false" StoreGeneratedPattern="Identity" /&gt;
            &lt;Property Name="ProcessNameId" Type="integer" Nullable="false" /&gt;
            &lt;Property Name="Amount" Type="integer" Nullable="false" /&gt;
            &lt;Property Name="Datetime" Type="datetime" Nullable="false" /&gt;
          &lt;/EntityType&gt;
        &lt;/Schema&gt;&lt;/edmx:StorageModels&gt;
      &lt;!-- CSDL content --&gt;
      &lt;edmx:ConceptualModels&gt;
        &lt;Schema xmlns="http://schemas.microsoft.com/ado/2008/09/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" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation"&gt;
          &lt;EntityContainer Name="Model1Container" annotation:LazyLoadingEnabled="true"&gt;
            &lt;EntitySet Name="ProcessNames" EntityType="Model1.ProcessName" /&gt;
            &lt;EntitySet Name="Usages" EntityType="Model1.Usage" /&gt;
            &lt;AssociationSet Name="ProcessNameUsage" Association="Model1.ProcessNameUsage"&gt;
              &lt;End Role="ProcessName" EntitySet="ProcessNames" /&gt;
              &lt;End Role="Usage" EntitySet="Usages" /&gt;
            &lt;/AssociationSet&gt;
          &lt;/EntityContainer&gt;
          &lt;EntityType Name="ProcessName"&gt;
            &lt;Key&gt;
              &lt;PropertyRef Name="Id" /&gt;
            &lt;/Key&gt;
            &lt;Property Type="Int64" Name="Id" Nullable="false" annotation:StoreGeneratedPattern="Identity" /&gt;
            &lt;Property Type="String" Name="Name" Nullable="false" MaxLength="2147483647" FixedLength="false" Unicode="true" /&gt;
            &lt;NavigationProperty Name="Usages" Relationship="Model1.ProcessNameUsage" FromRole="ProcessName" ToRole="Usage" /&gt;
          &lt;/EntityType&gt;
          &lt;EntityType Name="Usage"&gt;
            &lt;Key&gt;
              &lt;PropertyRef Name="Id" /&gt;
            &lt;/Key&gt;
            &lt;Property Type="Int64" Name="Id" Nullable="false" annotation:StoreGeneratedPattern="Identity" /&gt;
            &lt;Property Type="Int64" Name="ProcessNameId" Nullable="false" /&gt;
            &lt;Property Type="Int64" Name="Amount" Nullable="false" /&gt;
            &lt;Property Type="DateTime" Name="Datetime" Nullable="false" /&gt;
            &lt;NavigationProperty Name="ProcessName" Relationship="Model1.ProcessNameUsage" FromRole="Usage" ToRole="ProcessName" /&gt;
          &lt;/EntityType&gt;
          &lt;Association Name="ProcessNameUsage"&gt;
            &lt;End Type="Model1.ProcessName" Role="ProcessName" Multiplicity="1" /&gt;
            &lt;End Type="Model1.Usage" Role="Usage" Multiplicity="*" /&gt;
          &lt;/Association&gt;
        &lt;/Schema&gt;
      &lt;/edmx:ConceptualModels&gt;
      &lt;!-- C-S mapping content --&gt;
      &lt;edmx:Mappings&gt;
      &lt;Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs"&gt;
    &lt;EntityContainerMapping StorageEntityContainer="Model1StoreContainer" CdmEntityContainer="Model1Container"&gt;
            &lt;EntitySetMapping Name="ProcessNames"&gt;
              &lt;EntityTypeMapping TypeName="Model1.ProcessName"&gt;
                &lt;MappingFragment StoreEntitySet="ProcessNames"&gt;
                  &lt;ScalarProperty Name="Name" ColumnName="Name" /&gt;
                  &lt;ScalarProperty Name="Id" ColumnName="Id" /&gt;
                &lt;/MappingFragment&gt;
              &lt;/EntityTypeMapping&gt;
            &lt;/EntitySetMapping&gt;
            &lt;EntitySetMapping Name="Usages"&gt;
              &lt;EntityTypeMapping TypeName="Model1.Usage"&gt;
                &lt;MappingFragment StoreEntitySet="Usages"&gt;
                  &lt;ScalarProperty Name="Datetime" ColumnName="Datetime" /&gt;
                  &lt;ScalarProperty Name="Amount" ColumnName="Amount" /&gt;
                  &lt;ScalarProperty Name="ProcessNameId" ColumnName="ProcessNameId" /&gt;
                  &lt;ScalarProperty Name="Id" ColumnName="Id" /&gt;
                &lt;/MappingFragment&gt;
              &lt;/EntityTypeMapping&gt;
            &lt;/EntitySetMapping&gt;
            &lt;AssociationSetMapping Name="ProcessNameUsage" TypeName="Model1.ProcessNameUsage" StoreEntitySet="Usages"&gt;
              &lt;EndProperty Name="ProcessName"&gt;
                &lt;ScalarProperty Name="Id" ColumnName="ProcessNameId" /&gt;
              &lt;/EndProperty&gt;
              &lt;EndProperty Name="Usage"&gt;
                &lt;ScalarProperty Name="Id" ColumnName="ProcessNameId" /&gt;
              &lt;/EndProperty&gt;
            &lt;/AssociationSetMapping&gt;
          &lt;/EntityContainerMapping&gt;
  &lt;/Mapping&gt;&lt;/edmx:Mappings&gt;
    &lt;/edmx:Runtime&gt;
    &lt;!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) --&gt;
    &lt;edmx:Designer xmlns="http://schemas.microsoft.com/ado/2008/10/edmx"&gt;
      &lt;edmx:Connection&gt;
        &lt;DesignerInfoPropertySet&gt;
          &lt;DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" /&gt;
        &lt;/DesignerInfoPropertySet&gt;
      &lt;/edmx:Connection&gt;
      &lt;edmx:Options&gt;
        &lt;DesignerInfoPropertySet&gt;
          &lt;DesignerProperty Name="ValidateOnBuild" Value="true" /&gt;
          &lt;DesignerProperty Name="EnablePluralization" Value="True" /&gt;
          &lt;DesignerProperty Name="IncludeForeignKeysInModel" Value="False" /&gt;
        &lt;/DesignerInfoPropertySet&gt;
      &lt;/edmx:Options&gt;
      &lt;!-- Diagram content (shape and connector positions) --&gt;
      &lt;edmx:Diagrams&gt;
        &lt;Diagram Name="Model1" &gt;
          &lt;EntityTypeShape EntityType="Model1.ProcessName" Width="1.5" PointX="0.75" PointY="0.75" Height="1.2636116536458317" /&gt;
          &lt;EntityTypeShape EntityType="Model1.Usage" Width="1.5" PointX="3" PointY="0.75" Height="1.7566536458333339" /&gt;
          &lt;AssociationConnector Association="Model1.ProcessNameUsage"&gt;
            &lt;ConnectorPoint PointX="2.25" PointY="1.4639794921875002" /&gt;
            &lt;ConnectorPoint PointX="3" PointY="1.4639794921875002" /&gt;
          &lt;/AssociationConnector&gt;
        &lt;/Diagram&gt;
      &lt;/edmx:Diagrams&gt;
    &lt;/edmx:Designer&gt;
  &lt;/edmx:Edmx&gt;
  </code></pre>
  
  <p>thanks</p>