Hi Paul
Sorry but your reference to DefaultManager undermines your case.
I know you use multiple managers. I cannot have confidence in your example when you reference any EntityManager (DefaultManager in this case) which might be different from the manager of the entity raising the OnPropertyChanged.
I have never, ever, seen two entities of the same type within the same EntityManager that have the same EntityKey. That's because it is not physically possible.
You can prove me wrong. But the only way to do so is if your test is something like:
object phantom =
this.EntityAspect.EntityManager
// This next line from your code is pure obfuscation
// and simply returns the same EntityManager you started with
.GetEntityGroup(this.GetType()).EntityManager
.FindEntity(this.EntityKey);
if (!ReferenceEquals(phantom, this))
throw new InvalidOperationException("2 entities in the same manager with the same key")
My bet is that either (a) "this" entity is a detached instance (highly probable) or (b) this.EntityAspect.EntityManager is not the same as ...KLIBDefaultManager
I'll say it again: it is improper to refer to a specific EntityManager from within an entity. You should always use the entity's own EntityManager which you can reach with this phrase: "this.EntityAspect.EntityManager".
If something seems strange, always check the EntityManager of the entity and always check the this.EntityAspect.EntityState to verify your assumptions. Otherwise you are bound to fool yourself.
My bet is that the entity invoking OnPropertyChanged is detached. Something is attempting to modify this detached entity when you don't think it should. Either that or the one in the collection is detached.
The next question is "why are you ... or why is the collection ... holding on to such an entity and how did it become detached?"
Can't answer that question without context. To get that context, you would be wise to narrow it down to a simple reproducible case.
Edited by WardBell - 27-Feb-2010 at 12:13am