title: EF4 POCO (not using T4): Mapping and metadata information could not be found for EntityType
body: <p>I have a pretty simple console project with an entity model (containing two simple entities), two handmade POCOs and a handmade Context class. The program fires a simple query against the DB and everything including LazyLoading works fine. </p>
  
  <p><em>The problem:</em> As soon as i add another Entity data model (even if i add an empty one), the calls to CreateObjectSet in Ef2PlaygroundModel_3Container throw the following exception:</p>
  
  <pre><code>Unhandled Exception: System.InvalidOperationException: Mapping and metadata information could not be found for EntityType 'EF2_Playground.Driver'.
    at System.Data.Objects.ObjectContext.GetTypeUsage(Type entityCLRType)
    at System.Data.Objects.ObjectContext.GetEntitySetFromContainer(EntityContainer container, Type entityCLRType, String exceptionParameterName)
    at System.Data.Objects.ObjectContext.GetEntitySetForType(Type entityCLRType, String exceptionParameterName)
    at System.Data.Objects.ObjectContext.CreateObjectSet[TEntity]()
    at EF2_Playground.Ef2PlaygroundModel_3Container.get_Drivers() in C:\...\Ef2PlaygroundModel_3Pocos.cs:line 64
    at EF2_Playground.Program.Main(String[] args) in C:\...\Program.cs:line 15
  </code></pre>
  
  <p>Does anyone have an idea about what is going wrong here?</p>
  
  <hr>
  
  <h2><strong>That is the working project:</strong></h2>
  
  <p><strong>Ef2PlaygroundModel_3.edmx:</strong></p>
  
  <p><img src="https://content.screencast.com/users/JRoppert/folders/Jing/media/79d776db-9ee3-42c2-8d27-43fd26af1993/2010-02-21_1909.png" alt="EF4 Data Model"></p>
  
  <p>Code Generation Strategy is set to "None"</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="Ef2PlaygroundModel_3.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" 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="Ef2PlaygroundModel_3StoreContainer"&gt;
            &lt;EntitySet Name="Cars" EntityType="Ef2PlaygroundModel_3.Store.Cars" store:Type="Tables" Schema="dbo"/&gt;
            &lt;EntitySet Name="Drivers" EntityType="Ef2PlaygroundModel_3.Store.Drivers" store:Type="Tables" Schema="dbo"/&gt;
            &lt;EntitySet Name="CarDriver" EntityType="Ef2PlaygroundModel_3.Store.CarDriver" store:Type="Tables" Schema="dbo"/&gt;
            &lt;AssociationSet Name="FK_CarDriver_Car" Association="Ef2PlaygroundModel_3.Store.FK_CarDriver_Car"&gt;
              &lt;End Role="Car" EntitySet="Cars"/&gt;
              &lt;End Role="CarDriver" EntitySet="CarDriver"/&gt;
            &lt;/AssociationSet&gt;
            &lt;AssociationSet Name="FK_CarDriver_Driver" Association="Ef2PlaygroundModel_3.Store.FK_CarDriver_Driver"&gt;
              &lt;End Role="Driver" EntitySet="Drivers"/&gt;
              &lt;End Role="CarDriver" EntitySet="CarDriver"/&gt;
            &lt;/AssociationSet&gt;
          &lt;/EntityContainer&gt;
          &lt;EntityType Name="Cars"&gt;
            &lt;Key&gt;
              &lt;PropertyRef Name="Id"/&gt;
            &lt;/Key&gt;
            &lt;Property Name="Id" Type="int" StoreGeneratedPattern="Identity" Nullable="false"/&gt;
            &lt;Property Name="Brand" Type="nvarchar(max)" Nullable="false"/&gt;
            &lt;Property Name="Model" Type="nvarchar(max)" Nullable="false"/&gt;
            &lt;Property Name="ReleaseDate" Type="datetime" Nullable="true"/&gt;
          &lt;/EntityType&gt;
          &lt;EntityType Name="Drivers"&gt;
            &lt;Key&gt;
              &lt;PropertyRef Name="Id"/&gt;
            &lt;/Key&gt;
            &lt;Property Name="Id" Type="int" StoreGeneratedPattern="Identity" Nullable="false"/&gt;
            &lt;Property Name="Name" Type="nvarchar(max)" Nullable="false"/&gt;
          &lt;/EntityType&gt;
          &lt;EntityType Name="CarDriver"&gt;
            &lt;Key&gt;
              &lt;PropertyRef Name="Cars_Id"/&gt;
              &lt;PropertyRef Name="Drivers_Id"/&gt;
            &lt;/Key&gt;
            &lt;Property Name="Cars_Id" Type="int" Nullable="false"/&gt;
            &lt;Property Name="Drivers_Id" Type="int" Nullable="false"/&gt;
          &lt;/EntityType&gt;
          &lt;Association Name="FK_CarDriver_Car"&gt;
            &lt;End Role="Car" Type="Ef2PlaygroundModel_3.Store.Cars" Multiplicity="1"/&gt;
            &lt;End Role="CarDriver" Type="Ef2PlaygroundModel_3.Store.CarDriver" Multiplicity="*"/&gt;
            &lt;ReferentialConstraint&gt;
              &lt;Principal Role="Car"&gt;
                &lt;PropertyRef Name="Id"/&gt;
              &lt;/Principal&gt;
              &lt;Dependent Role="CarDriver"&gt;
                &lt;PropertyRef Name="Cars_Id"/&gt;
              &lt;/Dependent&gt;
            &lt;/ReferentialConstraint&gt;
          &lt;/Association&gt;
          &lt;Association Name="FK_CarDriver_Driver"&gt;
            &lt;End Role="CarDriver" Type="Ef2PlaygroundModel_3.Store.CarDriver" Multiplicity="*"/&gt;
            &lt;End Role="Driver" Type="Ef2PlaygroundModel_3.Store.Drivers" Multiplicity="1"/&gt;
            &lt;ReferentialConstraint&gt;
              &lt;Principal Role="Driver"&gt;
                &lt;PropertyRef Name="Id"/&gt;
              &lt;/Principal&gt;
              &lt;Dependent Role="CarDriver"&gt;
                &lt;PropertyRef Name="Drivers_Id"/&gt;
              &lt;/Dependent&gt;
            &lt;/ReferentialConstraint&gt;
          &lt;/Association&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="Ef2PlaygroundModel_3" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation"&gt;
          &lt;EntityContainer Name="Ef2PlaygroundModel_3Container" annotation:LazyLoadingEnabled="true"&gt;
            &lt;EntitySet Name="Cars" EntityType="Ef2PlaygroundModel_3.Car"/&gt;
            &lt;EntitySet Name="Drivers" EntityType="Ef2PlaygroundModel_3.Driver"/&gt;
            &lt;AssociationSet Name="CarDriver" Association="Ef2PlaygroundModel_3.CarDriver"&gt;
              &lt;End Role="Car" EntitySet="Cars"/&gt;
              &lt;End Role="Driver" EntitySet="Drivers"/&gt;
            &lt;/AssociationSet&gt;
          &lt;/EntityContainer&gt;
          &lt;EntityType Name="Car"&gt;
            &lt;Key&gt;
              &lt;PropertyRef Name="Id"/&gt;
            &lt;/Key&gt;
            &lt;Property Type="Int32" Name="Id" Nullable="false" annotation:StoreGeneratedPattern="Identity"/&gt;
            &lt;Property Type="String" Name="Brand" Nullable="false"/&gt;
            &lt;Property Type="String" Name="Model" Nullable="false"/&gt;
            &lt;Property Type="DateTime" Name="ReleaseDate" Nullable="true"/&gt;
            &lt;NavigationProperty Name="Drivers" Relationship="Ef2PlaygroundModel_3.CarDriver" FromRole="Car" ToRole="Driver"/&gt;
          &lt;/EntityType&gt;
          &lt;EntityType Name="Driver"&gt;
            &lt;Key&gt;
              &lt;PropertyRef Name="Id"/&gt;
            &lt;/Key&gt;
            &lt;Property Type="Int32" Name="Id" Nullable="false" annotation:StoreGeneratedPattern="Identity"/&gt;
            &lt;Property Type="String" Name="Name" Nullable="false"/&gt;
            &lt;NavigationProperty Name="Cars" Relationship="Ef2PlaygroundModel_3.CarDriver" FromRole="Driver" ToRole="Car"/&gt;
          &lt;/EntityType&gt;
          &lt;Association Name="CarDriver"&gt;
            &lt;End Type="Ef2PlaygroundModel_3.Car" Role="Car" Multiplicity="*"/&gt;
            &lt;End Type="Ef2PlaygroundModel_3.Driver" Role="Driver" 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="Ef2PlaygroundModel_3StoreContainer" CdmEntityContainer="Ef2PlaygroundModel_3Container"&gt;
            &lt;EntitySetMapping Name="Cars"&gt;
              &lt;EntityTypeMapping TypeName="IsTypeOf(Ef2PlaygroundModel_3.Car)"&gt;
                &lt;MappingFragment StoreEntitySet="Cars"&gt;
                  &lt;ScalarProperty Name="Id" ColumnName="Id"/&gt;
                  &lt;ScalarProperty Name="Brand" ColumnName="Brand"/&gt;
                  &lt;ScalarProperty Name="Model" ColumnName="Model"/&gt;
                  &lt;ScalarProperty Name="ReleaseDate" ColumnName="ReleaseDate"/&gt;
                &lt;/MappingFragment&gt;
              &lt;/EntityTypeMapping&gt;
            &lt;/EntitySetMapping&gt;
            &lt;EntitySetMapping Name="Drivers"&gt;
              &lt;EntityTypeMapping TypeName="IsTypeOf(Ef2PlaygroundModel_3.Driver)"&gt;
                &lt;MappingFragment StoreEntitySet="Drivers"&gt;
                  &lt;ScalarProperty Name="Id" ColumnName="Id"/&gt;
                  &lt;ScalarProperty Name="Name" ColumnName="Name"/&gt;
                &lt;/MappingFragment&gt;
              &lt;/EntityTypeMapping&gt;
            &lt;/EntitySetMapping&gt;
            &lt;AssociationSetMapping Name="CarDriver" TypeName="Ef2PlaygroundModel_3.CarDriver" StoreEntitySet="CarDriver"&gt;
              &lt;EndProperty Name="Car"&gt;
                &lt;ScalarProperty Name="Id" ColumnName="Cars_Id"/&gt;
              &lt;/EndProperty&gt;
              &lt;EndProperty Name="Driver"&gt;
                &lt;ScalarProperty Name="Id" ColumnName="Drivers_Id"/&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="False"/&gt;
          &lt;DesignerProperty Name="CodeGenerationStrategy" Value="None"/&gt;
        &lt;/DesignerInfoPropertySet&gt;
      &lt;/edmx:Options&gt;
      &lt;!-- Diagram content (shape and connector positions) --&gt;
      &lt;edmx:Diagrams&gt;
        &lt;Diagram Name="Ef2PlaygroundModel_3"&gt;
          &lt;EntityTypeShape EntityType="Ef2PlaygroundModel_3.Car" Width="1.5" PointX="3.25" PointY="1.625" Height="1.787985026041667"/&gt;
          &lt;EntityTypeShape EntityType="Ef2PlaygroundModel_3.Driver" Width="1.5" PointX="5.375" PointY="1.625" Height="1.59568359375"/&gt;
          &lt;AssociationConnector Association="Ef2PlaygroundModel_3.CarDriver"&gt;
            &lt;ConnectorPoint PointX="4.75" PointY="2.422841796875"/&gt;
            &lt;ConnectorPoint PointX="5.375" PointY="2.422841796875"/&gt;
          &lt;/AssociationConnector&gt;
        &lt;/Diagram&gt;
      &lt;/edmx:Diagrams&gt;
    &lt;/edmx:Designer&gt;
  &lt;/edmx:Edmx&gt;
  </code></pre>
  
  <p><strong>app.config:</strong></p>
  
  <pre><code>&lt;configuration&gt;
    &lt;connectionStrings&gt;
      &lt;add 
        name="Ef2PlaygroundModel_3Container" 
        connectionString="metadata=res://*/Ef2PlaygroundModel_3.csdl|res://*/Ef2PlaygroundModel_3.ssdl|res://*/Ef2PlaygroundModel_3.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;Data Source=.\SqlExpress;Initial Catalog=Ef2PlaygroundModel_3;Integrated Security=True;MultipleActiveResultSets=True&amp;quot;" 
        providerName="System.Data.EntityClient" 
      /&gt;
    &lt;/connectionStrings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p><strong>Ef2PlaygroundModel_3Pocos.cs:</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Data.Objects;
  
  namespace EF2_Playground
  {
    public class Car
    {
      public Car()
      {
        Drivers = new List&lt;Driver&gt;();
      }
  
      public int Id { get; set; }
      public string Brand { get; set; }
      public string Model { get; set; }
      public DateTime? ReleaseDate { get; set; }
  
      public virtual List&lt;Driver&gt; Drivers { get; private set; }
    }
  
    public class Driver
    {
      public Driver()
      {
        Cars = new List&lt;Car&gt;();
      }
  
      public int Id { get; set; }
      public string Name { get; set; }
  
      public virtual List&lt;Car&gt; Cars { get; private set; }
    }
  
    public class Ef2PlaygroundModel_3Container : ObjectContext
    { 
      public Ef2PlaygroundModel_3Container()
        : base("name=Ef2PlaygroundModel_3Container") 
      {
        ContextOptions.LazyLoadingEnabled = true;
      }
  
      public IObjectSet&lt;Car&gt; Cars
      {
        get { return CreateObjectSet&lt;Car&gt;(); }
      }
  
      public IObjectSet&lt;Driver&gt; Drivers
      {
        get { return CreateObjectSet&lt;Driver&gt;(); }
      }
    }
  }
  </code></pre>
  
  <p><strong>Program.cs:</strong></p>
  
  <pre><code>using System;
  
  namespace EF2_Playground
  {
    class Program
    {
      static void Main(string[] args)
      {
        using (var ctx = new Ef2PlaygroundModel_3Container())
        {
          foreach (var driver in ctx.Drivers)
          {
            Console.WriteLine(driver.Name);
            foreach (var car in driver.Cars)
            {
              Console.WriteLine("   drives a {0} - {1} (released on {2})", car.Brand, car.Model, car.ReleaseDate);
            }
          }
        }
      }
    }
  }
  </code></pre>
  
  <p><strong>And finally Model1.edmx that breaks the whole thing as soon as i add it to the project:</strong></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 xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl" Namespace="Model1.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2005"&gt;
          &lt;EntityContainer Name="Model1TargetContainer"&gt;
          &lt;/EntityContainer&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;/EntityContainer&gt;
        &lt;/Schema&gt;
      &lt;/edmx:ConceptualModels&gt;
      &lt;!-- C-S mapping content --&gt;
      &lt;edmx:Mappings&gt;
        &lt;Mapping xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs" Space="C-S"&gt;
          &lt;Alias Key="Model" Value="Model1"/&gt;
          &lt;Alias Key="Target" Value="Model1.Store"/&gt;
          &lt;EntityContainerMapping CdmEntityContainer="Model1Container" StorageEntityContainer="Model1TargetContainer"&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="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;/edmx:Diagrams&gt;
    &lt;/edmx:Designer&gt;
  &lt;/edmx:Edmx&gt;
  </code></pre>