Mapping and metadata information could not be found for EntityType 'Schema.Klant'.
An exception that took me quite a lot of time while working with the entity framework is the “Mapping and metadata information could not be found for EntityType ‘Schema.Klant'” exception.
The Schema.Klant is an POCO so there is no automatic generation of the domain objects. The entity model is as shown below, this is a simplified model but it shows the problem.
The Klant and Adres class is shown below.
namespace Schema
{
public class Klant
{
public int Id { get; set; }
public Adres Adress { get; set; }
public string Voornaam { get; set; }
public string Achternaam { get; set; }
public string Tussenvoegsel { get; set; }
public int leeftijd { get; set; }
}
public class Adres
{
public int Id { get; set; }
public string Straat { get; set; }
public string Postcode { get; set; }
public string Woonplaats { get; set; }
public int Huisnummer { get; set; }
}
}
The exception suggests that it cannot find the metadata for the type Klant. So I checked the name of the class and the name of Entity in the entity model, they were the same. After spending a lot of time trying to solve the problem I found out that it was the leeftijd property in the Klant class that was not capitalized. Changed the leeftijd property to match the name of the property in the entity framework entity and it all works.
It would be nice if a more descriptive exception was thrown when a property isn’t in the POCO class. Maybe something like could not find mapping for property ‘leeftijd’ in class Schema.Klant.
