1:1的关系问题EF模型优先 [英] 1:1 relationship problems with EF Model First

查看:206
本文介绍了1:1的关系问题EF模型优先的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发一个应用程序的模型 - 先用EF。我想尽一切办法完成一个表的分裂模式和1:1的关系,但看起来像EF只是没有让我

I'm trying to develop an application as Model-First with EF. I tried everything to accomplish a table-splitting pattern and a 1:1 relationship but looks like EF just doesn't let me.

假设我使用模型的第一 - 有没有办法把一个1:1的关系不搞乱与生成的文件和EF让那个讨厌的:

Assuming I do use Model-First - is there a way to put a 1:1 relationship without messing with the generated files and EF giving that annoying:

多重不是在关系中的作用Blablalah有效   Blabalbala。由于从属角色属性都不是关键   性能,上层的从属地位的多重的约束   必须是*。

Multiplicity is not valid in Role 'Blablalah' in relationship 'Blabalbala'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be *.

我已经尝试对目标表设置我的FK的主键,但仍然于事无补。

I already tried to set my FK's as Primary Keys on destination tables but still doesn't help.

推荐答案

1:1的关系,一般通过在第一表的外键,然后让它在级联删除,数据库设计定义的

1:1 relationship is generally defined by having foreign key in the first table and then having it cascade on delete, in database design.

IE浏览器:用户表和UserProperties表。用户表将有UserPropertiesId为外键和UserProperties将基本上把用户尽可能多的用户一个UserProperties。这只是事情的是,如果你只用用户表中选择,不是一个问题。

IE: Users table and UserProperties table. Users table would have a UserPropertiesId as the foreign key and UserProperties would essentially treat Users as many Users to one UserProperties. That's just how things are, and if you only select by Users table it isn't an issue.

这篇关于1:1的关系问题EF模型优先的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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