从实体模型生成的对象不会创建可为空的外键
当涉及到数据库中可为空的外键时,我注意到一些奇怪的行为。我刚刚开始使用实体框架,所以我可能做错了什么,但我无法弄清楚这一点。
假设我有以下两个表:(CountryID 是可以为空的外键)
当我创建一个新的实体模型时,我最终得到以下结果:
但 CountryID 属性设置为 Nullable(无) - 而不是 True。显然,这是一个非常简单的示例,但对于大型数据库,手动切换所有这些将很困难。有没有办法让实体框架对这些外键使用可为空的 int?
?
I have noticed some strange behavior when it comes to nullable foreign keys in my database. I have just started playing with the entity framework so I'm probably doing something wrong, but I cannot figure this one out.
Say I have the following two tables: (CountryID is a foreign key that is nullable)
When I create a new entity model I end up with this:
But the CountryID properties are set to Nullable (None) - instead of True. Obviously this is a really trivial example, but with a large database it would be difficult switch all of these manually. Is there any way to have the entity framework use a nullable int?
for these foreign keys?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论