4

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!!

2
  • 4
    Sounds like a weird DB schema. Do all your tables have real PKs and FKs? Do you use any views or procs? You shouldn't get DefiningQuery with proper schemata. Commented Jul 22, 2010 at 17:18
  • Please add/elaborate on your DB schema and the relations between them. If your schema is correct then its the way you are adding thats incorrect. At the first guess it seems you are adding the object in the wrong order/way. Commented Jul 23, 2010 at 9:28

3 Answers 3

1

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

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.