EF Database First refusing to map a table

99封情书 提交于 2019-12-11 17:45:33

问题


I'm generating a model (EDMX) from a SQL Server database, and each time I generate it, it omits one table. I've tried deleting/recreating the table in the database and deleting/recreating the model but it still happens.

The table is a many-to-many linking table:

Companies (CompanyID, Name)
Sectors (SectorID, Name)
Companies_Sectors (CompanyID, SectorID) <-- this table doesn't get mapped

There are many identically structured tables that do get mapped so it's baffling me. I created this one just like the other ones - composite primary key and then the two foreign keys.

When I open the Model.edmx.diagram XML file it looks like this:

<EntityTypeShape EntityType="Model.Companies_Markets" Width="1.5" PointX="21" PointY="37.625" IsExpanded="true" />
<!-- ... -->
<AssociationConnector Association="Model.Companies_Sectors" ManuallyRouted="false" />

('Companies_Markets' is a similar table and that one is mapped fine). It seems like EF just won't recognise 'Companies_Sectors' as a table for some reason. Never had this issue before, what could be the problem?


回答1:


Bridge tables, which only contain the 2 Primary Keys of the linked tables are not supposed to show up.

Further information can be found here:

http://smehrozalam.wordpress.com/2010/06/29/entity-framework-queries-involving-many-to-many-relationship-tables/



来源:https://stackoverflow.com/questions/19478912/ef-database-first-refusing-to-map-a-table

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