Is it possible to use this pattern with signletone dbcontext?

Apr 21, 2015 at 1:35 AM
I have a problem with updating entity.
After first use of it, it stays in DbSet.Local cache and when i try to update it i got following error:
  "Message": "An error has occurred.",
  "ExceptionMessage": "Attaching an entity of type 'Krutopridumal.Entities.Models.ArtistModel' failed because another entity of the same type already has the same primary key value. This can happen when using the 'Attach' method or setting the state of an entity to 'Unchanged' or 'Modified' if any entities in the graph have conflicting key values. This may be because some entities are new and have not yet received database-generated key values. In this case use the 'Add' method or the 'Added' entity state to track the graph and then set the state of non-new entities to 'Unchanged' or 'Modified' as appropriate.",
  "ExceptionType": "System.InvalidOperationException",
  "StackTrace": "   в System.Data.Entity.Core.Objects.ObjectContext.VerifyRootForAdd(Boolean doAttach, String entitySetName, IEntityWrapper wrappedEntity, EntityEntry existingEntry, EntitySet& entitySet, Boolean& isNoOperation)\r\n   в System.Data.Entity.Core.Objects.ObjectContext.AttachTo(String entitySetName, Object entity)\r\n   в System.Data.Entity.Internal.Linq.InternalSet`1.<>c__DisplayClassa.<Attach>b__9()\r\n   в System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)\r\n   в System.Data.Entity.Internal.Linq.InternalSet`1.Attach(Object entity)\r\n   в System.Data.Entity.Internal.InternalEntityEntry.set_State(EntityState value)\r\n   в System.Data.Entity.Infrastructure.DbEntityEntry`1.set_State(EntityState value)\r\n   в LongLe.Repository.Pattern.Ef6.DatabaseContext.SyncObjectState[TEntity](TEntity entity) в C:\\Projects\\krutopridumal\\server\\Repository.Pattern.Ef6\\DatabaseContext.cs:строка 116\r\n   в LongLe.Repository.Pattern.Ef6.Repository`1.Update(TEntity entity) в C:\\Projects\\krutopridumal\\server\\Repository.Pattern.Ef6\\Repository.cs:строка 84\r\n   в KrutoPridumal.Domain.Services.ArtistService.UpdateArtist(ArtistModel artistModel) в C:\\Projects\\krutopridumal\\server\\KrutoPridumal.Domain\\Services\\ArtistService.cs:строка 81\r\n   в KrutoPridumal.API.Controllers.ArtistController.UpdateArtist(Int32 id, ArtistViewModel viewModel) в C:\\Projects\\krutopridumal\\server\\KrutoPridumal.API\\Controllers\\ArtistController.cs:строка 86"
Marked as answer by lelong37 on 5/12/2015 at 10:48 AM
May 12, 2015 at 5:42 PM
Please post your implementation.