EF不会在表中生成外键关联 [英] EF does not generate foreign key association from foreign key in table

查看:305
本文介绍了EF不会在表中生成外键关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表tblEvent和另一个表tblContact。在tblEvent中有一个字段ContactID,它通过外联链接到tblContact中的ContactID。我已经三重检查了外键在数据库中。



实体框架模型不会像其他外键一样生成导航属性和外键关联。 p>

这个外键可能有所不同,EF不会为其生成导航属性?



谢谢! / p>

解决方案

我在这里找到解决方案:



为什么EF 4不会与FK关系产生与唯一索引的列的关联?



原因是不认识这是因为表在外键字段上有一个唯一的非聚集索引。



显然,一个独特的非聚集索引允许一个无法映射的空值。


I have a table tblEvent and another table tblContact. There is a field ContactID in tblEvent that is linked by a foreign key to ContactID in tblContact. I've triple checked; the foreign key is in the database.

The Entity Framework model DOES NOT generate a navigation property and foreign key association for it as it does for the other foreign keys.

What could be different about this foreign key that EF does not generate a navigation property for it?

Thanks!

解决方案

I found the solution here:

Why doesn't EF 4 generate association for FK relation to column with unique index?

The reason it was not recognizing it is was because the table had a unique non-clustered index on the foreign key field.

Apparently, a unique, non-clustered index allows for a null value which can't be mapped.

这篇关于EF不会在表中生成外键关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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