Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3222884
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:02:34+00:00 2026-05-17T16:02:34+00:00

I am using an ObservableCollection to wrap some of my generated entity framework objects.

  • 0

I am using an ObservableCollection to wrap some of my generated entity framework objects.
When the user wants to edit some values , i am opening a popup windows that contains fields, and when the user changes and press save – the changes are saved to the database, and the binded controls are changes as it is an observablecollection.

To prevent the user from working on the same binded object (it causes the visual change of every binded control on the same time) i want to use some functionality the clone the object, and then detach the original, attach the cloned object, and save it to the database. The problem is that the cloned object does not save properly to the database. If i try only to detach the object, edit and then attach – when detached it loses all its parent and child refernces…

What is the CRUD standard in WPF? How can i cleanly edit a current row, while keeping it in an ObservableCollection?

Please Help….

Oran

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:02:34+00:00Added an answer on May 17, 2026 at 4:02 pm

    Well it seems that i have found a fine solution.

    1. First implement your cloneable object container :

      public class ClonableObjectContainer : Object , ICloneable
      {
          private Object data;
      
          public ClonableObjectContainer(Object obj)
          {
              data = obj;
          }
      
          public Object Data
          {
              get { return data; }
          }
      
          public object Clone()
          {
              return (ClonableObjectContainer)this.MemberwiseClone();
          }
      }
      
    2. Then use this object with its Clone method to create your detached edit object:

               ClonableObjectContainer coc = new ClonableObjectContainer(actor);
               EntityObject editEntity = (EntityObject)coc.Data;
      
    3. After performing changes, detach the original object from the ObjectContext
      , attach the cloned object, change its state to EntityState.Modified and gracefully save:

              ContextManager.CurrentObjectContext.Detach(oldItem);
              ContextManager.CurrentObjectContext.Attach((IEntityWithKey)item);
              ContextManager.CurrentObjectContext.ObjectStateManager.ChangeObjectState(item, EntityState.Modified); 
              ContextManager.Save();
      

    Hope it helps…
    Oran

    EDIT : If the followings does not work for you, please check the continued discussion : Entity Framework Attach Exception After Clone

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I am using an ObservableCollection within a WPF application, the application is an
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using C#, I need a class called User that has a username, password, active
Using MVVM and EF...I have a datagrid binding to a View Model (using ObservableCollection).
I've put together a WPF application using ObservableCollection and Dependency Properties which is cool
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.