Stephen, After having burned many hours with EF trying to understand "why"s, I have come to the conclusion to find ( EF or non-EF ) workarounds instead.
I have even seen the champion of EF, Julie Lerman post to MS newsgroups questioning the rational behind the very same behavior I was trying to understand ( it was about using EF in an N-Tier disconnected way). I guess the question one ends up asking themselves boils down to whether they are trying to use EF to accomplish some task or doing EF to understand EF itself. Having said that, EF does solve many problems but at the price of introducing a different types of problems. Question is which problem set one wishes rather be solving. Regards Arjang On 28 March 2011 14:24, Stephen Price <[email protected]> wrote: > Hey there, > > Are there any EF gurus about? > This is a further email about the issue I posted recently where pressing > escape to undo a new row on a RadGridView is throwing an exception on some > entities but not others. > > I've tracked down a difference but can't seem to find anything about > SourceSets. > > > > public void Remove(object value) > { > T entity = value as T; > if (entity != null) > { > this.Source.Remove(entity); > if (this._addedEntities.Contains(entity)) > { > this._addedEntities.Remove(entity); > this.Source.SourceSet.Remove(entity); > } > } > } > > > This is the code i've decompiled to see what's happening... > > the line with the sourceset.remove is throwing an exception because the > sourceset is null. I guess you could say that's a bug? I mean it's checking > if _addedEntities contains the entity before it removes it, but does not > check if the SourceSet contains the entity before trying to remove it. I > don't know enough about the EntityFramework to know what a SourceSet is... > may just be an internal only structure or something else? > > > int index = -1; > if (entity.EntitySet == this) > { > index = this._list.IndexOf(entity); > } > if (index == -1) > { > throw new InvalidOperationException(Resource.EntitySet_EntityNotInSet); > } > > > Inside the remove (second code snippit above) it checks if the entity is not > in the set and throws an InvalidOperationException. > > By that, I'm taking it that the entity not being in the SourceSet is an > exceptional circumstance. Just can't figure out what that means, right now. > > Feel like i'm learning to firewalk here :) > > cheers, > Stephen
