Need help using entities for ASP.NET MVC 2 framework

∥☆過路亽.° 提交于 2019-12-10 15:25:55

问题


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


回答1:


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

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




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/3304916/need-help-using-entities-for-asp-net-mvc-2-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!