Why does the ObjectStateManager property not exist in my db context?

C#Entity Framework

C# Problem Overview


I need to return a list of newly added objects from my database context.

I have read that i have to use ObjectStateManager for this purpos. The problem is, that my database context does not have the ObjectStateManager property.

The context works fine for retrivieing, adding and updating objects though.

I am using EF 5.0

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

What can i do?

C# Solutions


Solution 1 - C#

Try this:

var manager = ((IObjectContextAdapter)dbContext).ObjectContext.ObjectStateManager;

Solution 2 - C#

Try this:

dbContext.Entry(entity).State = EntityState.Modified;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKenciView Question on Stackoverflow
Solution 1 - C#Hamlet HakobyanView Answer on Stackoverflow
Solution 2 - C#Yared T GView Answer on Stackoverflow