New Posts New Posts RSS Feed: Async Navigation in SL with PropertyChanged events
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Async Navigation in SL with PropertyChanged events

 Post Reply Post Reply
Author
tj62 View Drop Down
Groupie
Groupie
Avatar

Joined: 21-May-2009
Location: Iceland
Posts: 81
Post Options Post Options   Quote tj62 Quote  Post ReplyReply Direct Link To This Post Topic: Async Navigation in SL with PropertyChanged events
    Posted: 21-Jan-2011 at 9:35am
Ah sorry I didn't notice the scroll bar: Here is the total copy/paste from that dialog:
 
Microsoft JScript runtime error: Unhandled Error in Silverlight Application Collection was modified; enumeration operation may not execute.   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at System.Collections.Generic.List`1.Enumerator.MoveNext()
   at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
   at IdeaBlade.Core.EnumerableFns.ForEach[T](IEnumerable`1 items, Action`1 action)
   at IdeaBlade.EntityModel.PendingEntityMap.Update(EntityWrapper pendingWrapper, EntityWrapper realWrapper)
   at IdeaBlade.EntityModel.ScalarEntityReference`1.InformPendingEntityOfRealEntity(EntityWrapper realEntity)
   at IdeaBlade.EntityModel.ScalarEntityReference`1.QueryCallback(EntityQueryOperation op)
   at IdeaBlade.EntityModel.BaseOperation`2.OnCompleted()
   at IdeaBlade.EntityModel.BaseOperation`2.IdeaBlade.EntityModel.IHasAsyncEventArgs.OnCompleted()
   at IdeaBlade.EntityModel.AsyncProcessor`1.<>c__DisplayClass2.<.ctor>b__0(TArgs args)
   at IdeaBlade.EntityModel.AsyncProcessor`1.Signal()
   at IdeaBlade.EntityModel.AsyncProcessor`1.<Execute>b__5(Object x)
 
If that helps, then I have a workaround that works:
In the view model I create this property:

        private const string _p_loggerName = "p_loggerName";

        public string p_loggerName

        {

            get

            {

                if (p_currentItem == null)

                    return null;

                return p_entOpcGroup.p_loggerLink.p_logger.p_name;

            }

        }

And then I use my LazyLoad service to grab the EntityAspect.PendingEntityResolved first for p_loggerLink ('b') and if that returns me not NullEntity in the resolved-event handler then I grab EntityAspect.PendingEntityResolved for p_logger ('c') and calls RaisePropertyChanged("p_loggerName");

       

 
Then I do the XMAL binding such:

Text="{Binding p_vm.p_loggerName, Source={StaticResource ViewModelLocator}, Mode=OneWay}"

My LazyLoad service checks if the 'b' navigation property is an NullEntity or not before it decides to grab PendignEntityResolved for navigation property 'c' and raise property changed event for "p_loggerName".  I could belive you forgot the null entity check of 'b'....just a theory :-)
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 21-Jan-2011 at 8:32am

tj262, can you also include a screen shot of the additional exception text?  It's cut off the stack trace where EnumerableFns.ForEach is called, and we'd like to see more of the stack trace to see what triggered the enumeration.

Back to Top
tj62 View Drop Down
Groupie
Groupie
Avatar

Joined: 21-May-2009
Location: Iceland
Posts: 81
Post Options Post Options   Quote tj62 Quote  Post ReplyReply Direct Link To This Post Posted: 21-Jan-2011 at 4:09am
Oh dam it, I was using 6.0.6. I upgraded and every thing works like a dream except on particular thing, that I think is a bug!
 
Let us call Navigation Property 'NP' in the description below.
If you have an entity 'a' that has a NP 'b' where 'b' has another NP 'c'. Then you want to bind to for example
a.b.c.name in XAML somthing like:
    Text="{Binding b.c.name, Mode=OneWay}"
where the the parent control has data context bound such:
    DataContext="{Binding a, Mode=TwoWay}"

This works fine as long as 'b' is not a NullEntity.  Unfortunately in my case b is nullable and therefore in that case the bound text box shold display empty. What happens however is that Visual Studio Just In Time Debugger pops up with this message:
An unhandled exception ('Unhandled Error in Silverlihgt Applicatoin Code: 4004
Categorey: ManagerdRuntimeError
Message: System.InvalidOperationException: Collection was modified;
enumeration operation may not execute.
Entering the debuger (if run without debugging) requests "eval code".
 
This is quite well known error indicating that a collection is modified in a foreach loop or similar.
 
I have uploaded screenshot from the debugger, as well as table structure I'm deailing with in the database when this happens if that helps:  uploads/508/NaviagationBug.zip
 
 
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 20-Jan-2011 at 11:13am
We actually did implement the feature proposed by pompomjuice in the 6.0.7 release.  In addition to the PendingEntityResolved and PendingEntityListResolved events, the PropertyChanged event will fire for the navigation property.
Back to Top
tj62 View Drop Down
Groupie
Groupie
Avatar

Joined: 21-May-2009
Location: Iceland
Posts: 81
Post Options Post Options   Quote tj62 Quote  Post ReplyReply Direct Link To This Post Posted: 20-Jan-2011 at 1:29am
I hit the same wall I think.  I have to hook everything up on the PendingEntityResolved event. To simplify that I created a "SericeLazyLoade.cs" class to avoid repeted code for this all over the place. And now I can do:

m_serviceLazyLoadDeviceItem = new ServiceLazyLoad(this, "p_currentItem", GetLazyEntity, true);

m_serviceLazyLoadDeviceItem.AddBoundProperty(typeof(EntDeviceItem), null, "p_deviceItemName");

m_serviceLazyLoadDeviceItem.AddBoundProperty(typeof(EntUom), null, "p_uomShortcut");

 
Wich will call OnPropertyChanged for the lazy loaded  "p_deviceItemName" and "p_uomShortcut" when loded.
But I sure agree with pompomJuce that having this out of the box would be very powerfull!!!
Is that planned?
Back to Top
pompomJuice View Drop Down
Newbie
Newbie
Avatar

Joined: 29-Jul-2010
Location: ZA
Posts: 28
Post Options Post Options   Quote pompomJuice Quote  Post ReplyReply Direct Link To This Post Posted: 21-Oct-2010 at 12:56am

That would be awesome.

I am using a RadCombobox at the moment and its selected item is bound to Entity.NavitionalProperty. That binding would cause a async navigation on NavigationalProperty which would then not update the UI because there is no PropertyChanged event for the binding to feed on :(
Currently trying to compensate by extending entities to scan all their navigational properties for pending events and calling OnPropertyChanged within them. But its a schlep.... and its not working for some reason.


Edited by pompomJuice - 21-Oct-2010 at 1:15am
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 20-Oct-2010 at 3:01pm
That's a good question!  We've opened a feature request to look into it.
Back to Top
pompomJuice View Drop Down
Newbie
Newbie
Avatar

Joined: 29-Jul-2010
Location: ZA
Posts: 28
Post Options Post Options   Quote pompomJuice Quote  Post ReplyReply Direct Link To This Post Posted: 20-Oct-2010 at 2:27am
I was wondering why you guys chose to only use PendingEntityResolved events to enable us to hook into Async navigational upades. Surely using the conventional PropertyChanged event fireing mechanism would work perfectly with async navigation.
 
Now I have to hook up all these updates manually where it just could have worked out of the box?
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down