|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Collection was modifiedHi List,
This is the exception I get recently: System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.Collections.ArrayListEnumeratorSimple.MoveNext() at Neo.Core.ObjectContext.FetchObjectsFromObjectTable(IFetchSpecification fetchSpec) in d:\ulka\visual studio projects\neo-1.4.0\src\neo\core\objectcontext.cs:line 1331 at Neo.Core.ObjectContext.GetObjects(IFetchSpecification fetchSpec) in d:\ulka\visual studio projects\neo-1.4.0\src\neo\core\objectcontext.cs:line 1259 at Neo.Framework.ObjectFactory.Find(IFetchSpecification fetchSpec) in D:\Ulka\Visual Studio Projects\neo-1.4.0\src\Neo\Framework\ObjectFactory.cs:line 51 at Neo.Framework.ObjectFactory.Find(Qualifier qualifier) in D:\Ulka\Visual Studio Projects\neo-1.4.0\src\Neo\Framework\ObjectFactory.cs:line 57 at Neo.Framework.ObjectFactory.Find(String qualifierFormat, Object[] parameters) in D:\Ulka\Visual Studio Projects\neo-1.4.0\src\Neo\Framework\ObjectFactory.cs:line 63 Here's the scenario: ObjectContext calls FetchObjectsFromStore and retrieves 1 record (which is actually all I need), then it calls FetchObjectsFromObjectTable. While looping through the retrieved objects (in my case 1 object), it evaluates them with the qualifier, which in turn retrieves a property value, which in turn retrieves a RelatedObject (in my case of same type), which in turn calls the database and retrieves a new object. Now the collection of in-memory objects has been modified -- Bang! More specifically, I have a Post object with a ParentPost property (which is also a Post object). I'm trying to retrieve all posts from a specific thread that have some ParentPost. There are two posts in this thread -- a parent and a child. Now, FetchObjectsFromStore retrieves the child post, which is what I need. Next, FetchObjectsFromObjectTable has to make sure the ParentPost property is not null. In order to do that, it retrieves the parent post, so the collection we iterate is modified. Workaround: retrieve all necessary objects before making the search. Performs better too. Fix: an obvious solution would be to clone the objecttable. Don't know how bad could that perform. My case is rather rare, so I'm not sure if it's worth it. A more smart fix would be to look at the query and somehow realize that the parent needs to be fetched. Similar to HitSpans. Complicated. The best would be to modify the qualifier, so that when it compares a property to null, it doesn't look for the related object, but calls something like IsDBNull for the corresponding column value (ParentPostID in my case). Complicated too, and spoils the beauty of EvaluateWithObject. So, I guess with could live with the existing situation, and it would suffice to just catch the exception and throw a more meaningful explanation, so that we users don't get puzzled. ulu --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Collection was modifiedOn 7 Jun 2006, at 20:21, Ulu wrote: > [...] > Here's the scenario: ObjectContext calls FetchObjectsFromStore and > retrieves 1 record (which is actually all I need), then it calls > FetchObjectsFromObjectTable. While looping through the retrieved > objects (in my case 1 object), it evaluates them with the > qualifier, which in turn retrieves a property value, which in turn > retrieves a RelatedObject (in my case of same type), which in turn > calls the database and retrieves a new object. Now the collection > of in-memory objects has been modified -- Bang! > > More specifically, I have a Post object with a ParentPost property > (which is also a Post object). I'm trying to retrieve all posts > from a specific thread that have some ParentPost. There are two > posts in this thread -- a parent and a child. Now, > FetchObjectsFromStore retrieves the child post, which is what I > need. Next, FetchObjectsFromObjectTable has to make sure the > ParentPost property is not null. In order to do that, it retrieves > the parent post, so the collection we iterate is modified. > > Workaround: retrieve all necessary objects before making the > search. Performs better too. > > Fix: an obvious solution would be to clone the objecttable. Don't > know how bad could that perform. My case is rather rare, so I'm not > sure if it's worth it. > > A more smart fix would be to look at the query and somehow realize > that the parent needs to be fetched. Similar to HitSpans. Complicated. > > The best would be to modify the qualifier, so that when it compares > a property to null, it doesn't look for the related object, but > calls something like IsDBNull for the corresponding column value > (ParentPostID in my case). Complicated too, and spoils the beauty > of EvaluateWithObject. > > So, I guess with could live with the existing situation, and it > would suffice to just catch the exception and throw a more > meaningful explanation, so that we users don't get puzzled. > > ulu > A really interesting problem indeed. I haven't really decided which option I like best but, like you suggest, in the meantime we should probably throw a better exception. Question is, under what condition exactly? Just catch an InvalidOperationException around the loop in FetchObjectsFromObjectTable? Saying that most likely the scenario you've desribed has occured? Also, can you file this as a bug so we don't lose track? erik --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
|
Re[2]: Collection was modifiedHi Erik,
Tuesday, June 13, 2006, 11:28:18 AM, I'm reading this: ED> A really interesting problem indeed. I haven't really decided which ED> option I like best but, like you suggest, in the meantime we should ED> probably throw a better exception. Question is, under what condition ED> exactly? Just catch an InvalidOperationException around the loop in ED> FetchObjectsFromObjectTable? Saying that most likely the scenario ED> you've desribed has occured? The best match would be to catch the InvalidOperationException *and* check if the collection's Count has been changed (so that we don't catch other InvalidOperations), then rethrow the original exception if it hasn't. If it has, we have our situation, so we'll need some explanations, and a wise advice. ED> Also, can you file this as a bug so we don't lose track? yep sure ulu --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
| Free embeddable forum powered by Nabble | Forum Help |