简体   繁体   English

首先使用数据库时如何防止EF6合并实体?

[英]How to prevent EF6 to merge entities when using database first?

I have three tables: user, specialUser and special 我有三个表:user,specialUser和special

User contains all the base fields. 用户包含所有基本字段。 specialUser has an id which is both, the FK (to user table) and PK and has another field specialId, which is a FK to the special table. specialUser具有一个ID,该ID既是FK(到用户表)又是PK,还有另一个字段specialId,它是特殊表的FK。

Now, when I add the tables to the edmx, EF has merged the specialuser with the user entity! 现在,当我将表添加到edmx时,EF已将specialuser与用户实体合并! User now has an extra navigation property to special. 用户现在具有一个额外的特殊导航属性。 I don't want this. 我不要这个 I want to have a separate entity for specialuser. 我想为specialuser提供一个单独的实体。

How can I force EF 6 not to merge these entities? 如何强制EF 6不合并这些实体?

I had that issue in the past, the only way I got the result I wanted is adding an extra column to the table, like EF_FIX bit nullable to the table. 我以前曾遇到过该问题,获得所需结果的唯一方法是在表中添加额外的列,例如EF_FIX位可为表设置为空。

add something like this to specialUser and it should do, i think, what you want 将这样的事情添加到specialUser ,它应该做,我想,你想要什么

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

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