Entity Framework generation missing an entity

扶醉桌前 提交于 2019-12-21 07:57:19

问题


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

Any advice would be greatly appreciated!


回答1:


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



来源:https://stackoverflow.com/questions/8915125/entity-framework-generation-missing-an-entity

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