表未映射到实体框架数据模型 [英] Table not mapped to Entity Framework Data Model

查看:78
本文介绍了表未映射到实体框架数据模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我已经开始使用EF了,但是遇到了问题.

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

概述:
我制作了一个EF模型,发现没有一个表(名为UserRoles)出现在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模型图

我试图通过更新数据模型"添加它

Problem Explained:
The original DB Diagram.

Partial EF Model Diagram

I tried to add it through "Update data model"

我试图将EF图中的实体重命名为"UserRoles",并弹出错误消息.

附言::我认为我已经很好地提出了问题,但是请让我知道您可能需要的其他信息.

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

推荐答案

好,您现在使用对象,不再需要sql.

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

使用EF,很多对很多关系不需要特殊的实体",而需要特殊的关系".

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.

如果关系表中至少具有onother属性("RelationName"字符串,例如-愚蠢的示例),则该属性将存在于EF模型中...

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...

不确定您需要什么:那只是对象"方式.考虑一下如果不使用数据库时如何创建这些类:可以在关系的每个部分中列出另一个.但是Sql无法做到这一点(数据库中不能有列表"),因此Sql需要一个关系表.但是EF是ORM,因此是对象,而不是sql.

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.

在代码优先"中创建关系的方式,但这很明确 http://blogs.msdn.com/b/wriju/archive/2011/05/14/code-first-ef-4-1-building-many-to-many-relationship.aspx

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

这篇关于表未映射到实体框架数据模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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