Need help using entities for ASP.NET MVC 2 framework

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

+4
source share
3 answers

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

Perhaps the problem is spelling "Parents" in the name of the connection table

+1
source

Your description is like one, many relationships. But in any case, please post your code snippet here to find out if there is a mistake in your statements. Bye Thomas Postscript This is a great way to format your code like this

 This is a line of code 

if you press the button with 101

0
source

make sure the GrandParents table as the primary key (identifier) ​​and rebuild the model

0
source

Source: https://habr.com/ru/post/1316484/


All Articles