简体   繁体   English

表未映射到实体框架数据模型

[英]Table not mapped to Entity Framework Data Model

Hi I'm back with another question,I have started using EF and I'm having problem with it. 嗨,我回来了另一个问题,我已经开始使用EF,我遇到了问题。

OverView: 概述:
I made an EF model ,and found out that one table (named UserRoles) didn't showed up in the EF Model Diagram ,I tried to add it through "Update data model" ,but wizard didn't showed me that table to add (as if it was already added) ,I also tried to refresh model through "Update data model" wizard it was not helpful. 我做了一个EF模型,发现一个表(名为UserRoles)没有出现在EF模型图中,我试图通过“更新数据模型”添加它,但是向导没有向我显示要添加的表(好像它已经添加了),我也尝试通过“更新数据模型”向导刷新模型它没有帮助。

Problem Explained: 问题解释:
The original DB Diagram. 原始DB图。
在此输入图像描述
Partial EF Model Diagram 部分EF模型图
在此输入图像描述
I tried to add it through "Update data model" 我尝试通过“更新数据模型”添加它
在此输入图像描述

I tried to rename an entity in the EF diargram to "UserRoles",an error message popped up. 我试图将EF diargram中的实体重命名为“UserRoles”,弹出一条错误消息。 在此输入图像描述

PS: I think I have presented the problem well ,but plz let me know of any more info u may need. PS:我想我已经很好地解决了这个问题,但是请告诉我你可能需要的更多信息。

Well, your working now with objects, no more sql. 好吧,你现在正在使用对象,没有更多的sql。

And with EF, many to many relationships don't need a special "entity", but a particular "relation". 对于EF,许多关系不需要特殊的“实体”,而是特定的“关系”。

In User class, you'll have a list of Roles, and in Roles class, a User list. 在User类中,您将拥有一个Roles列表,在Roles类中,您将拥有一个User列表。 Which represent perfectly a simple many to many relationship. 这代表了一个简单的多对多关系。

If you had at least onother property in your relation table (a "RelationName" string, for - stupid - example), then it would exist in the EF model... 如果你的关系表中至少有另一个属性(一个“RelationName”字符串,对于--stupid - 例子),那么它将存在于EF模型中......

EDIT : Not sure of what you need : that's just the "object" way. 编辑:不确定你需要什么:这只是“对象”的方式。 Think of the way you would create these classes if you weren't working with a Database : you would do a List of the other in each part of relation. 如果您不使用数据库,请考虑创建这些类的方式:您将在关系的每个部分中执行另一个列表。 But Sql can't do that (you can't have a "list" in a database), so Sql needs a relation table. 但是Sql不能这样做(你不能在数据库中有一个“列表”),所以Sql需要一个关系表。 But EF is an ORM, so object, not sql. 但是EF是一个ORM,所以对象,而不是sql。

EDIT 2 : 编辑2:

The way you would create your relation in Code First, but it's quite explicit http://blogs.msdn.com/b/wriju/archive/2011/05/14/code-first-ef-4-1-building-many-to-many-relationship.aspx 您在Code First中创建关系的方式,但它非常明确http://blogs.msdn.com/b/wriju/archive/2011/05/14/code-first-ef-4-1-building-many一对多,relationship.aspx

For more answers, just google "Entity framework many to many" sould do the trick 对于更多答案,只需谷歌“实体框架多对多”可以做到这一点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM