开发者

Need help using entities for ASP.NET MVC 2 framework

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 开发者_Go百科to add to the database in a special order because of the many to many relationships?

Thanks!!


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

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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜