EF数据库首先拒绝映射表 [英] EF Database First refusing to map a table

查看:130
本文介绍了EF数据库首先拒绝映射表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从SQL Server数据库生成一个模型(EDMX),每次生成它时,都省略一个表。我尝试删除/重新创建数据库中的表,并删除/重新创建模型,但仍然会发生。



该表是一个多对多链接表:



公司(CompanyID,Name)

部门(SectorID,Name)

Companies_Sectors(CompanyID,SectorID)< ; - 这个表没有被映射



有许多相同结构化的表, do 被映射,所以这让我很困惑。我创建了一个就像其他的 - 复合主键,然后是两个外键。



当我打开 Model.edmx.diagram XML文件看起来像这样:

 < EntityTypeShape EntityType =Model.Companies_MarketsWidth = 1.5PointX =21PointY =37.625IsExpanded =true/> 
<! - ... - >
< AssociationConnector Association =Model.Companies_SectorsManuallyRouted =false/>

('Companies_Markets'是一个类似的表格,映射得很好)。看来EF似乎不会因为某些原因认出Companies_Sectors作为表格。从来没有这个问题,可能是什么问题?

解决方案

桥表,只包含链接的2个主键表不应该出现。



可以在这里找到更多信息:



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


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?

解决方案

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/

这篇关于EF数据库首先拒绝映射表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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