简体   繁体   English

实体框架重新创建相关实体

[英]Entity framework re-create related entities

  1. I create new instance of some entity 我创建某个实体的新实例
  2. I load a few another instances 我再加载几个实例
  3. I set them as reference in new instance 我将它们设置为新实例中的参考
  4. I save but EF create refernces instance one more time 我保存但EF再创建一次引用实例

You should read this article, Why Does Entity Framework Reinsert Existing Objects into My Database? 您应该阅读这篇文章, 为什么实体框架将现有对象重新插入到我的数据库中? , by Julie Lerman. ,朱莉·勒曼(Julie Lerman)撰写。 She explains very well why this can occur and how you can avoid it. 她很好地解释了为什么会发生这种情况以及如何避免这种情况。

If there is a relation in database between entities (tables), then upon saving parent object, all the child objects will also be saved if they are not null. 如果数据库中实体(表)之间存在关系,则在保存父对象时,如果所有子对象都不为null,则还将保存所有子对象。

You are probably saving parent entity and then also saving child entities again. 您可能正在保存父实体,然后又保存了子实体。

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

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