Author |
Share Topic Topic Search Topic Options
|
afrizal.chen
Newbie
Joined: 17-Dec-2008
Location: Singapore
Posts: 21
|
Post Options
Quote Reply
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 ....
|
 |
kimj
IdeaBlade
Joined: 09-May-2007
Posts: 1391
|
Post Options
Quote Reply
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.
|
 |
afrizal.chen
Newbie
Joined: 17-Dec-2008
Location: Singapore
Posts: 21
|
Post Options
Quote Reply
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.
|
 |
davidklitzke
IdeaBlade
Joined: 14-Jun-2007
Posts: 715
|
Post Options
Quote Reply
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:
|
 |
pucsoftware
Groupie
Joined: 15-Apr-2008
Location: United States
Posts: 46
|
Post Options
Quote Reply
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
|
 |
kimj
IdeaBlade
Joined: 09-May-2007
Posts: 1391
|
Post Options
Quote Reply
Posted: 22-Apr-2009 at 11:54am |
|
 |