Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(13)
就我而言,另一位开发人员已从数据库的表中删除了该字段。意识到这一点后,从实体模型中删除该表并将其添加回来解决了问题。
In my case, another developer had deleted the field from the table in the database. Having realised this, removing the table from the entity model and adding it back solved the problem.
我现在遇到了这个问题...需要使用 Visual Studio 中的设计器向现有表添加一个标量属性(例如
custom_property
)。我可以从数据库更新模型,但这不是一个选择。它在模型中造成了很多错误。这是一个巨大的数据库模型,我需要添加此属性的表可能有 30 多个关系。我只是想映射这个新的
custom_property
列,该列已添加到名为custom_table
的表中。直接在设计器中添加标量属性后,抛出以下异常:
在 VS 的错误列表中显示:
错误 11009:属性“ ”未映射
我采取的修复步骤this:
.edmx
文件;custom_table
;.edmx
XML 代码。这些是我必须添加映射的地方:
和
I hit this problem right now... Needed to add a scalar property, let's say
custom_property
to an existing table using the Designer in Visual Studio.I could've updated the Model from the Database but that was not an option. It was causing a lot of errors in the Model. It's a huge database model and the table I needed to add this property has maybe more than 30 relationships. I just wanted to map this new
custom_property
column that got added to the table namedcustom_table
.After adding the scalar property directly in the designer, the following exception was being thrown:
In the
Error List
in VS this was being shown:Error 11009: Property ' ' is not mapped
Steps I took to fix this:
.edmx
file in Visual Studio Code;custom_table
;.edmx
XML code with mappings.These were the places where I had to add mappings:
and
您不能简单地将数据库中的表添加到模型中,然后在模型中创建新的关联。默认情况下,它使用独立关联,该关联必须映射到其数据库对应项=该关系也必须存在于数据库中。您必须 将您的关系建模为 FK 关联,但它仅允许一对一和一对多关联。 此处描述了关联类型之间的差异。
You cannot simply add tables from the database into your model and then create a new association in the model. By default it uses independent association which must be mapped to its database counterpart = the relation must exists in the database as well. You must model your relation as FK association but it allows only one-to-one and one-to-many associations. Differences between association types are described here.
当我在更改连接字符串后最终“从数据库更新模型”时,我遇到了这个问题。
通过右键单击实体并打开和关闭某个键,它似乎导致了刷新并解决了问题。这看起来更像是实体框架的一个错误。
应该注意的是,在本例中我使用的是 MySQL 连接器,所以我怀疑它总体上相当挑剔。
I've had this problem when i ended up 'updating model from database' after having changed the connection string.
By right clicking the entity and toggling a key on and off It seems to have caused a refresh and has fixed the problem. This seems more like a bug with the Entity framework.
It should be noted in this case i was using the MySQL connector so I suspect it's just rather finicky in general.
如果模型上有不可映射的属性,您可能会收到此错误。
例如,我将一些
Linq2Sql
转换为EF6
,并且在Binary
字段上出现错误。 Binary 是System.Data.Linq
类型,但对于 EF,它需要是byte[]
。更改它解决了问题。You can get this error if you have a property on the model that isn't mappable.
For instance I was converting some
Linq2Sql
over toEF6
and had an error on aBinary
field. Binary is aSystem.Data.Linq
type but for EF it needs to bebyte[]
. Changing it fixed the problem.在 EF 6 中遇到了类似的问题:
问题是我直接在文本编辑器中对数据库优先 EF 应用程序的 *.edmx 文件进行了更改,而不是使用设计器。因此,只需恢复文本更改并使用设计器应用它们,错误就会消失。在设计器中点击保存即可更新关联的 *.msl 文件。
Experienced a similar problem with EF 6:
The problem turned out to be that I had made a change to the *.edmx file for my database-first EF application directly in a text editor instead of using the designer. So just reverted the text changes and applied them using the designer and the error went away. Hitting save in the designer is what updated the associated *.msl file.
我从 Linqpad 收到此错误,无法弄清楚为什么它突然开始发生,以及这是否会成为我使用上下文的应用程序中的问题。我还刚刚删除了最近由新实体创建的类,然后右键单击 .tt 文件并点击“运行到光标”以重新生成该类。这为我解决了。
I was getting this error from Linqpad and could not figure out why it started happening all of a sudden and whether this would be an issue in my application using the context. I also just deleted the class that was recently created by a new entity and then I right clicked on the .tt file and hit "run to cursor" to regenerate the class. That fixed it for me.
从数据库更新模型选项对我不起作用。
因此,我需要先删除所有实体,然后再从数据库更新模型才能成功修复解决方案。
Updating Model from Database option doesn't work for me.
So I need to delete all entities first before updating model from database to successfully fix the solution.
如果您已在实体上应用映射,请尝试从表中删除该列,这将解决问题
If you have applied a mapping on the entity, try to remove that column from the table which will resolve the issue
就我而言,我的数据库管理员已将列名称从大写更改为小写。
我通过再次更新该表(从数据库更新模型)解决了该问题。然后,删除之前的大写列。
In my case, my database administrator has changed column names from uppercase to lower.
I solved the problem by updating (update model from database) for that table again. Then, deleted previous uppercase columns.
就我而言,我重命名了表中的字段并添加了主键。之后,我得到了那个错误。我转到对象/模型列表,将其删除并从数据库刷新后,我再次遇到相同的错误。我尝试了几次但没有任何结果。 EF 生成的类是旧表结构和新表结构的混合体。
研究了一段时间,解决办法是这样的:
转到您的实体的图表。找到您的表格或在右侧打开模型资源管理器(右键单击图表 - 打开模型资源管理器)。在 ...Model、...Model.Store 下搜索您的模型/表并将其删除。之后,再次从数据库添加表,问题解决。
In my case, I had renamed a field in a table and added a primary key. After that, I got that error. I went to my list of objects/models and after delete it and refresh from the database, I had again the same error. I tried several times but nothing. The class that EF was generating was a mix between the old table structure and the new one.
After investigating for a while, this is the solution:
Go to the Diagram of your your entities. Locate your table or open on your right the Model Explorer (right click over the diagram - Open model explorer). Search for your model/table under ...Model, ...Model.Store and delete it. After that, add again the table from the database and problem solved.
就我而言,在解决方案中,首先我刷新了 MyProjectname.edmx 文件,但它不起作用。然后我删除了我修改过的表,并再次更新了模型表单数据库(不刷新它)。它起作用了。
in my case,in solution at first I refreshed MyProjectname.edmx file but it didn't work .Then I deleted the table that I had modified it and again updated the Model form database (not refresh it).And it works.
就我而言,不允许修改现有表,但我发现当您添加一个新表并在 EF4 中选中“在模型中包含外键列”并且该表不包含任何外键关系时,您会尝试添加关联的话就会触发这个错误。
在 EF4 模型中定义约束数据库中不存在
如果链接的文章消失,解决方案是:
您需要打开关联的属性窗口,然后单击引用约束省略号以获取引用约束对话框。然后为“从属属性”设置选择正确的字段。
In my case am not allowed to modify existing tables but I discovered that when you add a new table with "Include foreign key columns in the model" checked in EF4 and the table doesn't contain any foreign key relationships then you try to add a association it will trigger this error.
Defining Constraints in an EF4 model that don’t exist in the database
In case the linked article disappears, The solution is:
You need to open the properties window of the association and then click on the Referential Constraint ellipses to get to the ref constraint dialog. Then select the correct field for the 'Dependent Property' setting.