为什么会出现这样的错误:没有以下的EntitySet / AssociationSet指定的映射 - 使用实体? [英] Why am I getting this error: No mapping specified for the following EntitySet/AssociationSet - Entity1?

查看:1371
本文介绍了为什么会出现这样的错误:没有以下的EntitySet / AssociationSet指定的映射 - 使用实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用实体框架4的模式第一种方法。

I'm using Entity Framework 4 with the Model First approach.

我开始这个项目,设计了实体和所产生的数据库。一切运行良好。

I started the project, designed the entities and generated the database. Everything worked fine.

然后,我需要回去和添加其他实体来我的模型。然而,正如我拖累了实体的EDMX我得到这个错误:

Then I needed to go back and add another entity to my model. However, as I drag an entity to the EDMX I get this error:

好吧!我只需要使用实体映射到表..但是,嘿!我使用的是型号第一种方式,我希望当我生成DDL以创建表给我。

Alright! I just need to map Entity1 to a table.. But hey! I'm using Model First approach, I expect it to create the table for me when I generate the DDL.

我如何解决这个问题?

推荐答案

这是因为EF4方式的工作原理与模型一。

This is because of the way EF4 works with model-first.

当你第一次创建一个模型,第一个模型,它在该SSDL不存在的状态。您可以拖动的实体,他们交往等等,然而,如果你看一看上EDMX文件SSDL,你会看到,没有任何实体有关联的存储表中SSDL。

When you first create a model-first model, it's in a state that the SSDL does not exist. You can drag entities, associate them and so forth and yet, if you take a look at the SSDL on the EDMX file, you will see that none of the entities have an associated storage table in the SSDL.

当你点击生成数据库从型号上下文菜单项的变化。混乱的是,这个动作并不仅仅是生成一个DDL脚本。事实上,它改变了EDMX文件以包括SSDL信息。从这点上,该EDMX文件将进入其中在设计每个实体/ CSDL必须映射到在SSDL一个实体的状态。如果一个人不映射,它会引发一个编译时错误:

That changes when you click the Generate Database From Model context menu item. The confusing part is that this action does more than simply generating a DDL script. In fact, it changes the EDMX file to include SSDL information. From this point on, the EDMX file will enter a state in which every entity in the designer/CSDL must map to an entity in the SSDL. If one does not map, it will trigger a compile time error:

没有指定映射下的EntitySet / AssociationSet - (的entityName)

No mapping specified for the following EntitySet/AssociationSet - (EntityName)

另一个有趣的事实是,它不是那种错误,将prevent汇编。它将,的确,生成输出类库。难道不应该是一个警告什么的?

Another interesting fact is that it's not the kind of error that will prevent compilation. It will, indeed, generate the output class library. Shouldn't it be a warning or something?

要prevent这个错误,你只插入一个新的实体后,要做的就是 重新生成数据库从型号。这将更新SSDL和修复映射。

To prevent this error, All you have to do after inserting a new entity is to Generate Database From Model again. That will update the SSDL and fix the mappings.

修改

如果您不使用模型的第一和你从数据库更新,你也会有你的数据库服务器中删除表的情况下,这个错误。这是因为实体框架将不会自动删除该实体为您服务。手动删除实体和错误就会消失。

If you are not using model-first and you "update from database", you will also have this error in the case you deleted a table in DB Server. This is because Entity Framework will not automatically delete the entity for you. Delete the entity manually and the error will go away.

这篇关于为什么会出现这样的错误:没有以下的EntitySet / AssociationSet指定的映射 - 使用实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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