I would like to understand something. When does an Entity get its 'IsRemoved' state? I've got a class called 'Contact' and somehow, somewhere it gets the state 'IsRemoved'. Because of this, I can not access any of its properties anymore.

I've overriden the OnRemove() and OnRemoving() methods to be able to set a breakpoint, but none of them gets ever called. Still the Entity has state 'IsRemoved'.

Regards Paul Sinnema Diartis AG

Updated at 09.07.2010 9:16:06


I don't think we produced a rollback anywhere so far. We don't do manual Transaction at the moment. So the only way a rollback could be influencing the behavior is when Automatic Transactions do a rollback.

I don't want to be rude, but I really believe there's a bug in there somewhere. What we do in our application is the following:

  • We add a Person Entity.
  • The Person adds default to its Navigations where needed (i.e. LastName, Address, Communication, CivilStatus and Nationality)
  • In our OnSaving method we stamp (CreatedOn, CreatedBy, ChangedOn and ChangedBy) our Entities. At that moment the IsRemoved = false.
  • We automatically save when a Tab changes in the TabControl. At the moment this takes place too when a new tab is added to the GUI, meaning the ApplyChanges() is executed.
  • After the ApplyChanges we execute our OnSaved method to allow post-processing (currently none is done). At that moment the IsRemoved for all Entities = true. We also see the Entities which are created by the Replay on the Session. These all have IsRemoved = false.

Conclusion: The ApplyChanges() changes IsRemoved from false to true.

Regards Paul Sinnema Diartis AG

This thread was imported from our support forum. The original discussion may contain more detailed answer.

asked Jul 08 '10 at 11:21

Paul%20Sinnema's gravatar image

Paul Sinnema

One Answer:

This may happen e.g. if you rollback a transaction where the object was just created.

In this case you won't get any notifications: from to point of DO object gets "removed" status during loading its state in new transaction. In this case no state change notifications are sent.

So being precise, object may enter "removed" state when:

  • It really gets removed in the current transaction

  • As result of state load attempt in new transaction, or after rollback of nested transaction inside continuing outermost transaction.

Note that state load attempt happens when you're trying to do something (e.g. read property) with an object which state currently isn't precisely known.

Clear then - you should read this: viewtopic.php?f=29&t=6006#p15140 (just published). I.e. in your case all the Entities with old keys (= keys before remapping) will be dead.

Let me illustrate this:

  • You create entity E with ID = -1, while DisconnectedState is attached.

  • Changes gets applied, -1 key is remapped to 10. DisconnectedState remaps the state associated with key=-1 to key=10.

  • You read E.SomeProperty. Since transaction is new here, Session asks for current state of this entity. DisconnectedState looks for state with key=-1, and finds nothing (because it is already remapped), so finally request does to the database, and nothing is returned here. DisconnectedState caches info that entity with key=-1 is removed, and returns this state to Session. That's what you see in UI.

  • On the other hand, if you'd query for Entity with key=10, you'd immediately get its correct state.

The solution here is to rebind the UI. Note that probably we could implement transparent Entity.Key change here, but this is very subjective from the point of other possible consequences. There are just few "axioms":

  • Key is immutable

  • Once read, Entity.Key always returns such currentKey that currentKey==originalKey.

answered Jul 09 '10 at 08:36

Alex%20Yakunin's gravatar image

Alex Yakunin

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA