Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 825
Kenci Avatar asked Nov 27 '12 09:11

Kenci


People also ask

What is ObjectStateManager?

ObjectStateManager tracks query results, and provides logic to merge multiple overlapping query results.

What is context in DB?

A DbContext instance represents a combination of the Unit Of Work and Repository patterns such that it can be used to query from a database and group together changes that will then be written back to the store as a unit. DbContext is conceptually similar to ObjectContext.


2 Answers

Try this:

var manager = ((IObjectContextAdapter)dbContext).ObjectContext.ObjectStateManager; 
like image 119
Hamlet Hakobyan Avatar answered Oct 02 '22 17:10

Hamlet Hakobyan


Try this:

dbContext.Entry(entity).State = EntityState.Modified; 
like image 23
Yared T G Avatar answered Oct 02 '22 19:10

Yared T G