需要帮助使用实体ASP.NET MVC 2框架 [英] Need help using entities for ASP.NET MVC 2 framework

查看:112
本文介绍了需要帮助使用实体ASP.NET MVC 2框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET MVC 2使用C#制作一个网站。我设计了一个数据库和一帮有多对多的关系表,类似以下内容:

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

母公司 - 多对多 - 儿童

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();

据崩溃与错误的的SaveChanges()行:

无法更新EntitySet的
  JunctionPartentsChilds,因为它
  有DefiningQuery无
   元素存在于
  ModificationFunctionMapping元素
  支持当前的操作。

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

编辑:
我可以通过删除所有在汽车的DefiningQuery元素修复这个错误产生的code,现在我就应该是更具描述在同一行得到一个错误,但我仍处于亏损状态。

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.

该错误是:无效的对象名称JunctionPartentsChilds ,它抛出一个UpdatingException

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?

谢谢!

推荐答案

如果您复制/粘贴此错误:
无效的对象名称JunctionPartentsChilds

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

也许问题是家长的交界处表名拼写错误

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

这篇关于需要帮助使用实体ASP.NET MVC 2框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆