Table not mapped to Entity Framework Data Model

匿名 (未验证) 提交于 2019-12-03 08:51:18

问题:

Hi I'm back with another question,I have started using EF and I'm having problem with it.

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.

Problem Explained:
The original DB Diagram.


Partial EF Model Diagram


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.

P.S: I think I have presented the problem well ,but plz let me know of any more info u may need.

回答1:

Well, your working now with objects, no more sql.

And with EF, many to many relationships don't need a special "entity", but a particular "relation".

In User class, you'll have a list of Roles, and in Roles class, a User list. 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...

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. But EF is an ORM, so object, not sql.

EDIT 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

For more answers, just google "Entity framework many to many" sould do the trick



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!