From: Nikolaus K. <par...@gm...> - 2017-03-01 14:41:38
|
Hello, I am currently using EF 6.x with Firebird 2.5.x and it works very well. During a dataload from an external datasource I load a number of records from my database and compare them with the external source. Sometimes I have to correct/complete my data. In the case this update fails on the database i detach the current entity that the following updates can continue. This works fine unless I have modified a navigation property of the current entity. List<RESSOURCEN> = this.RESSOURCEN.Where(a => a.RESSOURCEN_STATUS == "Aktiv").Include(b => b.ARBEITSZEITEN).ToList(); // I loop through the List<RESSOURCEN> // I modify one of the navigation properties ARBEITSZEITEN // The update fails this._efContext.Entry(res).State = EntityState.Detached; // Now the entity RESSOURCEN res is detached and all navigation properties are set to null. I understand the reason for that, following this page: http://stackoverflow.com/questions/10342445/why-does-setting-entitystate-to- detached-empty-a-property-of-type-listt#10343174 // I tried to detach the navigation property before the entity itself, but this fails: Change of items in the enumeration I am currently looping through. Foreach(ARBEITSZEITEN azneu in res.ARBEITSZEITEN) { this._efContext.Entry(azneu) State = EntityState.Detached; } // I added now the modified navigation properties to my own list, which I use then the detach. modifiedAZ.Add(az); // In the case of a error during update on the database Foreach(ARBEITSZEITEN azneu in modifiedAZ) { this._efContext.Entry(azneu) State = EntityState.Detached; } modifiedAZ.Clear(); How would you handle such a situation? Thanks Niko |