简体   繁体   English

具有密钥(PK)的实体不会往返

[英]An Entity with Key (PK) will not round-trip

I have two tables: <subjects> and <prerequisites> . 我有两个表: <subjects><prerequisites> The primary key of prerequisite table is a composite key: pr_subject_id and pr_prerequisite_subject_id . 先决条件表的主键是一个组合键: pr_subject_idpr_prerequisite_subject_id They are both foreign keys from the <subjects> table. 它们都是<subjects>表中的外键。 I can map the pr_subject_id in a association but i can't map the return trip ( pr_prerequisite_subject_id ). 我可以在关联中映射pr_subject_id,但不能映射回程( pr_prerequisite_subject_id )。 See image. 见图片。 How should i solve this? 我该如何解决?

note : When i made the associations in sql server it was fine but when i loaded the database in the entity framework, the entity framework dropped the prerequisite table because of this return trip association. 注意 :当我在sql server中建立关联时,这很好,但是当我在实体框架中加载数据库时,由于此返回行程关联,实体框架删除了先决条件表。

在此处输入图片说明

在此处输入图片说明

I looked around but i think this is a common problem with the Entity Framework. 我环顾四周,但我认为这是实体框架的常见问题。 I found two workarounds here . 我在这里找到两个解决方法。 Basically what i did was adding a third column er_id and let that be the primary key. 基本上,我所做的是添加第三列er_id并将其作为主键。 Then to enforce that there will be no double of the other two columns i added a unique constraint. 然后为了强制在其他两列中都没有加倍,我添加了一个唯一约束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM