Questions tagged [objectstatemanager]

30 questions
34
votes
3 answers

unexpected GetType() result for entity entry

While I iterating through ObjectStateEntries I expected [t] variable name will be MY_ENTITY foreach (ObjectStateEntry entry in context.ObjectStateManager.GetObjectStateEntries(EntityState.Deleted)) { Type t = entry.Entity.GetType(); …
20
votes
4 answers

Unable to attach a detached entity: "An object with the same key already exists in the ObjectStateManager"

I am trying to attach an entity to the ObjectContext. When I do so, the following InvalidOperationException is thrown: An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with…
Shimmy Weitzhandler
  • 92,920
  • 119
  • 388
  • 596
15
votes
4 answers

ObjectContext.Refresh()?

How to update ALL the dirty entities from the data store, and reset their changed values to the original store value? The method ObjectContext.Refresh requires as a parameter the entities to be refreshed.
4
votes
3 answers

How do I foreach through my dbcontext entities in EF 4.1?

I'm using ASP.NET Entity Framework 4.1 MVC 3 (C#) I want to foreach through all the entities in my DbContext. I need to be able to dynamically refer to my entities in order to make dynamic views. I have read Lerman's book, two MVC (2 & 3) books,…
4
votes
1 answer

Problem with UPDATE Operation On Entity Framework 4 (Pure POCOs)

I have an Entity Framework 4.0 model implemented with pure POCO's (no code generation, no self-tracking entities, just plain old CLR objects). Now, here is some code i have in my UI to perform an UPDATE: [HttpPost] public ActionResult…
RPM1984
  • 69,608
  • 55
  • 212
  • 331
4
votes
3 answers

EF ObjectStateEntry OriginalValues contains CurrentValues

I am trying to override Entity Framework's SaveChanges() method to save auditing information. I begin with the following: public override int SaveChanges() { ChangeTracker.DetectChanges(); ObjectContext ctx =…
Carel
  • 1,849
  • 8
  • 28
  • 58
3
votes
2 answers

Why does Entity Framework detect changes on properties which were modified but reset?

If I modify a property of a POCO Entity, but reset it the EntityFramework still says that there are changes. Property "Name": Value "Test" (original value) -> Value "Test123" (value changed by UI) -> Value "Test" (value…
3
votes
1 answer

Nullreference exception in EntityFramework ObjectStateManager.DetectConflicts

I've written a WCF webservice that takes XML files and stores them into the database. Everything worked fine under 'low load' but under high load I'm getting some unexpected behavior and thusfar I haven't been able to pinpoint what exactly the…
3
votes
2 answers

ObjectStateManager error while adding second data (Entity Framework)

When I adding more than one consecutive data an error occurred in SaveChanges() method. EXCEPTION The changes to the database were committed successfully, but an error occurred while updating the object context. The ObjectContext might be in an…
2
votes
1 answer

EntityDataSource Null Update Pameters not getting marked Modified

I am using an EntityDataSource with a FormView on VB.NET application. The FormView contains an AjaxControlToolKit TabContains with multiple tabs. Due to the fact that each tab is a naming container, Bind doesn't work properly for updating values (as…
2
votes
1 answer

MVC5/EF6: Object cannot be deleted because it was not found in the ObjectStateManager?

I have the following HttpPost Delete() method which was working in my MVC5 app. To the best of my knowledge nothing relating to this controller, the View, or even the model has changed. // POST: Admin/UserManagement/Delete/5 [HttpPost,…
1
vote
1 answer

Why do I get referenced entities added to context instead of attached, unchanged?

I have attached entities to a context with EntityState.Unchanged which will be referenced by a new entity I add later via DbContext.Add(). The Add() adds the entity, but it also adds the other entities it references to the added collection in…
Kit
  • 15,260
  • 3
  • 47
  • 87
1
vote
1 answer

How to find out which entity is inside the ObjectStateManager more then once

Hi i get the following error: AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager. Make sure that the key values are unique before calling AcceptChanges. Now i'm trying to fix…
Nick V
  • 633
  • 5
  • 16
1
vote
0 answers

Dealing with complex properties with Entity Framework's ChangeTracker

I'll try and be as descriptive as I can in this post. I've read a dozen or more SO questions that were peripherally related to my issue, but so far none have matched up with what's going on. So, for performing audit-logging on our database…
1
vote
2 answers

Entity Framework Update Existing Object

I have added a row to my database and come back with a different context to update it. I have this class: public abstract partial class DataManager where C : class, IDomainObject, I, new( ) where I : IDomainObject C might be an…
1
2