实体框架生成缺少实体 [英] Entity Framework generation missing an entity

查看:88
本文介绍了实体框架生成缺少实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ADO.NET实体数据模型项从SQL数据库生成实体,并使用ADO.NET DbContext Generator从那里生成实体.当我从数据库生成edmx时,设计器中似乎缺少我的实体之一,但是当我查看edmx背后的代码时,我在代码中看到了它,而当我生成dbContext时,根本没有生成该实体. ..

I'm trying to generate my entities from my SQL database using the ADO.NET Entity Data Model item and from there using the ADO.NET DbContext Generator. When I generate my edmx from the database one of my entities seems to be missing in the designer but when I look at the code behind of the edmx I see it in code and when I generate the dbContext the entity isn't generated at all...

任何建议将不胜感激!

推荐答案

如果缺少实体的表是多对多关系的联接表,则在创建表时不会获得实体类数据库中的模型.当表有两列构成一个组合主键,而每一列是另外两个表的外键时,EF就会意识到这一点.

If the table you are missing an entity for is a join table for a many-to-many relationship you don't get an entity class when you create a model from the database. EF recognizes this when the table has two columns which form a composite primary key and each column is a foreign key to two other tables.

EF在内部管理联接表,并且不将其公开为实体.您只有左"和右"实体,并且导航集合彼此指向.如果通过在这些集合中添加或删除元素来添加或删除关系,则当您调用SaveChanges时,EF将为联接表创建正确的INSERT和DELETE语句.但这是内部发生的,对您完全隐藏了.

EF manages the join table internally and doesn't expose it as an entity. You only have the "left" and the "right" entity with navigation collections pointing to each other. If you add or remove a relationship by adding or removing elements to those collections EF will create the correct INSERT and DELETE statements for the join table when you call SaveChanges. But this happens internally and is completely hidden to you.

换句话说:一切都很好.

In other words: Everything is OK.

这篇关于实体框架生成缺少实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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