Confuse about tracking in EF (updating entity with child collection)

c# entity-framework entity-framework-6

Popular Answer

Think on the following to gain a better understanding of the entity framework:DbContext between your application and the database as a proxy. TheDbContext unless you instruct it otherwise, will cache everything and use every piece of information from the cached values.

For 1.: Depending on your surroundings, whether yourDbContext is not disposed between choosing and changing the entities, you can callSaveChanges you can save your data. When yourDbContext is disposed, it is possible to remove the entities from the context, alter the data, reattach the entities, and set theEntityState to change.

Because I stopped utilizing the entity framework around six months ago, I can't guarantee a response. But I am aware that updating complicated relations is difficult.

For 2.: The instructionAsNoTracking instructs the EF not to keep track of any modifications made to the entities contained in this query. For instance, you might choose five TimeSheets from your database, modify the first entity's information, and delete the last one. TheDbContext if you call, it understands that the first entity has been altered and the last one has been erased.SaveChanges the DbContext update the first entity automatically, remove the final one, and leave the other ones alone. Now you attempt to update an entity independently while reassociating the first entity with the DbContext.

Now that two entities with the same key exist in the DbContext, your exception is the result.

zzz-59: TheDynamicProxies is the object used by the entity framework to keep track of these entities' modifications.

For 4.: Check out this link. An excellent book about entity framework 6 is also available (Title: "Programming Entity Framework")

10/6/2015 8:38:21 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow