Error 11010
How to make inheritance in Entity Frameworks
0Hello Guys, since my last post I had some problems when I tried to make some inheritance relationship using entity Framework. After one weekend I Figured out the why I was doing wrong. So I’ll explain how to solve these problems and make your inheritance relationship works.
1º The first Thing to do is create a console application that we’ll use to test our model.
2º Download my DataBase sample backup and restore it in your machine.
3º Add a new ADO.NET Entity Data Model, Generate this model using a existent DataBase, select the database that you restored and select all tables. After it you have a model that contains these tables:
Now You can see that we can make some inheritance relationship. One of these is the inheritance between Person and Academic Person. So academic person is a specific kind of person. Let’s make this inheritance. As you can read in a lot of blogs and sites you have to do some phases to achieve the inheritance. so, the first step is delete the relationship between the tables that you want make the inheritance.
1-delete the relationship between Person and academic Person.
2- Create an inheritance relationship between Person and Academic Person. Right click in person entity and select inheritance.
3- After the inheritance had been done you can see that the Primary key in AcademicPerson(AcademicPersonID) isn’t a primary key anymore. So just think, if academic person inherits person they have to have the same key, so you have to delete the property.
4-After delete the key you have to set the mapping for academicPersonID to PersonID, because as we thought both have to be equals.
After these steps you should be able to use inheritance, but when you try to validate your model you get This message:
Error 11010: Association End ‘AcademicPerson’ is not mapped
I Looked for this error but I get just nonsense answer. So I tried by myself to solve this problem. After some hours I found the solution, this messages means:
The AcademicPerson entity is related to others entities in its model, so if you change the primary key academicPersonID you have to change all relationships to academicPersonEntity.
If you look count the error messages you’ll se that there are four messages and there are four relationships to academicperson too. Therefore, to solve this problem you have to change the relationships, So right-click in the relationship between AcademicPerson and AcademicPersonKnowledgeArea, select table mapping and in the line you see PersonID set the other key to AcademicPersonID.
To solve the error 11010 you have to do the same to all relationships. After it you should be able to validate your model.So now you can use inheritance. Now let’s use our inheritance in our console application.
ComperioBlogEntities Context = new ComperioBlogEntities();
AcademicPerson academicPerson = new AcademicPerson();
academicPerson.AcademicOrganization = Context.AcademicOrganization.FirstOrDefault();
academicPerson.AddressNumber = “01″;
academicPerson.BirthDate = DateTime.Now.Date;
academicPerson.City = “Rio de Janeiro”;
academicPerson.Country = “Brasil”;
academicPerson.EducationLevel = Context.EducationLevel.FirstOrDefault();
academicPerson.Email = “mail@mail.com”;
academicPerson.Enrolment = “0814700001″;
academicPerson.LattesPlatformWebPage = “www.programmingandliving.blogspot.com”;
academicPerson.Name = “Higor”;
academicPerson.Neighbourhood = “VP”;
academicPerson.State = “RJ”;
academicPerson.Street = “ABC Street”;
academicPerson.WebPage = “www.programmingandliving.blogspot.com”;
academicPerson.ZipCode = “21225″;
Context.AddToPerson(academicPerson);
Context.SaveChanges();
If you try to execute you’ll get the error bellow.
This is easy to fix, it means that you have to set off the identity column in academicPerson table. Otherwise the EF cannot set the Same ID of PersonID. So set off the Identity of AcademicPersonID and run your application.
So, I had some other problems but these were the worst ones.
KeyWords:
Entity Framework inheritance erros
Error 11010: Association End is not mapped
An error occurred while updating the entries. See the InnerException for details.