views:

217

answers:

3

I'm making a site in ASP.NET MVC 2 using C#. I designed a database with a bunch of tables that have many to many relationships, similar to the following:

GrandParent - many to many - Parent

and

Parent - many to many - Child

I used the Entity Framework to make all of the entities class and am now working on a function in a repository class which adds a GrandParent.

It tries to create Child, add it to a Parent, then add the parent to a GrandParent and then add the GrandParent to the database by using the command

entities.GrandParents.AddObject(newGrandParent);
entities.SaveChanges();

It crashes on the SaveChanges() line with the error:

Unable to update the EntitySet 'JunctionPartentsChilds' because it has a DefiningQuery and no element exists in the ModificationFunctionMapping element to support the current operation.

EDIT: I can fix that error by deleting all of the DefiningQuery elements in the auto generated code and now I'm getting an error on the same line that should be more descriptive but I'm still at a loss.

The error is: Invalid object name 'JunctionPartentsChilds' and it throws a UpdatingException.

Any ideas what's going wrong? Do you have to add to the database in a special order because of the many to many relationships?

Thanks!!

A: 

Your description looks like to one to many relationsships. But anyway, please post your code fragment here, to see if there's an error in your statements. Bye Thomas P.S. Ther's a wonderful way to format your code like this

This is a line of code

if you klick the button with the 101

Thomas Poth
+1  A: 

If you copy/pasted this error: Invalid object name 'JunctionPartentsChilds'

Maybe the problem is the misspelling of "Parents" in the junction table name

RyanHennig
+1 I saw that right away.
JungleFreak
A: 

make sure that GrandParents table as a primarykey(identity) and rebuild the model

Rony