EF Model First 的 1:1 关系问题

1:1 relationship problems with EF Model First(EF Model First 的 1:1 关系问题)

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

问题描述

我正在尝试使用 EF 将应用程序开发为 Model-First.我尝试了一切来实现表格拆分模式和 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.

假设我确实使用 Model-First - 有没有办法建立 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"中无效'布拉巴巴拉'.因为从属角色属性不是关键属性,从属角色的多重性的上限必须是 *.

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:用户表和用户属性表.用户表将有一个 UserPropertiesId 作为外键,而 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.

这篇关于EF Model First 的 1:1 关系问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:EF Model First 的 1:1 关系问题

基础教程推荐