I am making a site in ASP.NET MVC 2 using C #. I developed a database with many tables that have many different relationships, similar to the following:
GrandParent - many for many - parent
and
Parent - many for many - Child
I used the Entity Framework to create all entity classes, and now I'm working on a function in the repository class that GrandParent adds.
He tries to create a Child, add it to Parent, then add a parent to GrandParent, and then add GrandParent to the database using the command
entities.GrandParents.AddObject(newGrandParent); entities.SaveChanges();
It crashes in the SaveChanges() with an error:
The EntitySet "JunctionPartentsChilds" could not be updated because it has a DefiningQuery and no element exists in the ModificationFunctionMapping element to support the current operation.
EDIT: I can fix this error by deleting all DefiningQuery elements in the automatically generated code, and now I get an error message on the same line, which should be more descriptive, but I'm still at a loss.
Error: Invalid object name 'JunctionPartentsChilds' , and it throws an UpdatingException.
Any ideas what goes wrong? Do I need to add a special order to the database due to many, many relationships?
Thanks!!
source share