New Posts New Posts RSS Feed: EntityManager.RejectChanges() throw  "Cannot call BeginEdit() on Deleted or Detached entities"
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

EntityManager.RejectChanges() throw "Cannot call BeginEdit() on Deleted or Detached entities"

 Post Reply Post Reply
Author
afrizal.chen View Drop Down
Newbie
Newbie
Avatar

Joined: 17-Dec-2008
Location: Singapore
Posts: 21
Post Options Post Options   Quote afrizal.chen Quote  Post ReplyReply Direct Link To This Post Topic: EntityManager.RejectChanges() throw "Cannot call BeginEdit() on Deleted or Detached entities"
    Posted: 20-Mar-2009 at 3:38am
Hi,
I'm creating 5 new entities that are related one to another, when I call EntityManager.RejectChanges() it throws InvalidOperationException {"Cannot call BeginEdit() on Deleted or Detached entities"}.
Here is the scenario:
1. EntityManager.FindEntities(EntityState.Added) <-- 5 entities (No Deleted, No Modified)
2. EntityManager.RejectChanges(), InvalidOperationException is thrown.
3. EntityManager.FindEntities(EntityState.Added) <-- 4 entities (No Deleted, No Modified)
    Here, the one entity that is gone is the FIRST entity that was created.
4. EntityManager.RejectChanges(), everything is fine.


These are the call stacks from the exception:
   at IdeaBlade.EntityModel.v4.Entity.System.ComponentModel.IEditableObject.BeginEdit()
   at System.Windows.Forms.CurrencyManager.OnCurrentChanged(EventArgs e)
   at System.Windows.Forms.CurrencyManager.ChangeRecordState(Int32 newPosition, Boolean validating, Boolean endCurrentEdit, Boolean firePositionChange, Boolean pullData)
   at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
   at System.Windows.Forms.BindingSource.OnListChanged(ListChangedEventArgs e)
   at System.Windows.Forms.BindingSource.InnerList_ListChanged(Object sender, ListChangedEventArgs e)
   at System.ComponentModel.BindingList`1.OnListChanged(ListChangedEventArgs e)
   at System.ComponentModel.BindingList`1.FireListChanged(ListChangedType type, Int32 index)
   at System.ComponentModel.BindingList`1.Child_PropertyChanged(Object sender, PropertyChangedEventArgs e)
   at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
   at IdeaBlade.EntityModel.v4.Entity.OnPropertyChanged(PropertyChangedEventArgs e)
   at IdeaBlade.EntityModel.v4.EntityGroup.OnEntityChanged(EntityChangedEventArgs e)
   at IdeaBlade.EntityModel.v4.EntityGroup.RemoveEntity(Entity entity)
   at IdeaBlade.EntityModel.v4.Entity.RejectChanges()
   at IdeaBlade.EntityModel.v4.EntityGroup.<RejectChanges>b__9(Entity e)
   at System.Collections.Generic.List`1.ForEach(Action`1 action)
   at IdeaBlade.EntityModel.v4.EntityGroup.RejectChanges()
   at IdeaBlade.EntityModel.v4.EntityCache.<RejectChanges>b__8(EntityGroup t)
   at IdeaBlade.Util.v4.ExtensionFns.ForEach[T](IEnumerable`1 items, Action`1 action)
   at IdeaBlade.EntityModel.v4.EntityCache.RejectChanges()
   at IdeaBlade.EntityModel.v4.EntityManager.RejectChanges()
   at ....
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 20-Mar-2009 at 2:16pm
I have been unable to reproduce the error you see.  In my tests, a RejectChanges() call detaches all Added entities, therefore returning 0 records in the second FindEntities() call, and no exceptions are thrown.  The "BeginEdit()" error message is coming from a bound UI control, which is still bound to the BindingSource whose data has effectively disappeared.  Check your handlers for the EntityChanging, EntityChanged and PropertyChanged events to see if they're behaving as expected.  If the problem persists, please send a solution which reproduces the problem to support.
Back to Top
afrizal.chen View Drop Down
Newbie
Newbie
Avatar

Joined: 17-Dec-2008
Location: Singapore
Posts: 21
Post Options Post Options   Quote afrizal.chen Quote  Post ReplyReply Direct Link To This Post Posted: 22-Mar-2009 at 8:19am
Hi,
Thanks for the hint.
I was using normal databinding using binding source, I modified it to use ControlBindingManager and it works fine now.
But I have another issue of using ControlBindingManager, When I bind it to DevExpress labelControl, it throws exception "could not locate a suitable binder for a LabelControl".
Well it works for System.Windows.Forms.Label, but It will looks different in my form.
Please advise. Thanks.
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 04-Apr-2009 at 9:10am
For a control to work with the ControlBindingManager, it needs a DataBinder.  We wrote one for the Windows Forms label, but not for the DevExpress label.  To see how to write a Custom Data Binder for a control, see:
 
Back to Top
pucsoftware View Drop Down
Groupie
Groupie
Avatar

Joined: 15-Apr-2008
Location: United States
Posts: 46
Post Options Post Options   Quote pucsoftware Quote  Post ReplyReply Direct Link To This Post Posted: 22-Apr-2009 at 11:18am
"For a control to work with the ControlBindingManager, it needs a DataBinder.  We wrote one for the Windows Forms label, but not for the DevExpress label.  To see how to write a Custom Data Binder for a control, see:
 
the above post refers to a link that describes how to write a custom data binder but the link isn't correct. It refers back to this post not a different one.
puctx
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 22-Apr-2009 at 11:54am
I think he meant to refer you here: http://www.ideablade.com/forum/forum_posts.asp?TID=133
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down