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.
11 comments
Hello, I am having the same problem, but the names are identical, as I can
solve?
Can you pass me the project to take a look?
Thank you
robson.deft@gmail.com
Robson
Also check that data types in the database match those in your code. If not, you will also receive this error.
Sunshine Coast Website Design
this saves me a day – thanks!
david
this saves me day – many thanks!
david
Hi. I was having the same problems and the names were totally identical. But yet, I decided to copy paste the names from the .cs class to the entity in the edmi file and viola.. it worked.. Just thought Id share my experiences….
Aisha
Thank you so much!
Orlando
if thats the case then the generated POCO should not be working as well when you add a new property in it manually ? but it is still working. issue is somewhere else.
Adeel
man, I was looking to a this exception for at least a day, and your post was the 20th I’ve read saying I should see if the names were the same in the database and in the class…. the properties were, the name of the class wasn’t… thank you!
Marcos
There is not each and every day that I did not visit your weblog, it is just so enjoyable and outstanding to be here day in reading your notions and your writings. Continue posting you have me hook my friend.
Cheap jordan shoes
Will not anticipate to cheap jordans best abdominal muscles by resorting to 1 ideal tummy workout but air jordan shoes flight 45 a combination of air jordan shoes 17.5 mid darkblue shoes in black exercises that do the Nike Air Max tn 10 net structure shoes in tan black your abdomen from unique angles! but all indications point to tory burch handbags No. it will be manageable to take intersections easy finish “breathtaking jump”;
wholesale jordans
the proposition does not let her give up the tory burch shoes heels of women altogether? You will never find its hangings save taking a closer look;
tory burch shoes