Silverlight, ReadOnlyListBase and Managed backing fields

Silverlight, ReadOnlyListBase and Managed backing fields

Old forum URL: forums.lhotka.net/forums/t/9828.aspx


pgroenenstein posted on Friday, December 03, 2010

Hi

If my understanding is correct CSLA for Silverlight (I'm currently using 3.8.4) has to make use of managed backing fields in order for serialization to work correctly.

My problem is that the "parent" in a read only list does not seem to have acces to "RegisterProperty". How would one go about to do it the right way then?

My need is such that the "parent" in a read only list has some data that it gets from the DB that needs to be loaded. E.g. I have a "Menu" readonly list(e.g. a "Breakfast Menu" which contains items on a menu( e.g. eggs, toast...etc). While the children in the list has managed backing fields and everything is just A OK there, the "parent" does not seem to have a way to make use of manged backing fields. I need this ability in thre parent to show for example the "time available" and the description of the menu (e.g. "Breakfast" menu)

What is the recommended way then to implement the concept of Managed backing fields in a "readonly list"?

Thank you

Phillip

 

 

 

pgroenenstein replied on Friday, December 03, 2010

I understand that I need to ovverride "OnGetState" and "OnSetState" but it returns an error when I run it. The Error is:

"The key given wasn't present in the dictionary". I understand what the error message mean, what I don't understand what is causing it?

Here is my code, what is wrong here?

   Protected Overrides Sub OnGetState(ByVal info As Csla.Serialization.Mobile.SerializationInfo, ByVal mode As Csla.Core.StateMode)

      MyBase.OnGetState(info, mode)

      info.AddValue("MyApp.MenuListItem._Descrip", _Descrip)

    End Sub

    Protected Overrides Sub OnSetState(ByVal info As Csla.Serialization.Mobile.SerializationInfo, ByVal mode As Csla.Core.StateMode)

        _Descrip = info.GetValue(Of String)("MyApp.MenuListItem._Descrip")

      MyBase.OnSetState(info, mode)

    End Sub

 

Thank You

pgroenenstein replied on Friday, December 03, 2010

I would think there is nothing wrong with the code, what I suspect is that "OnGetState" is not putting the variable into to serialzed stream when fetching from the DB..any suggestions why not?

 

pgroenenstein replied on Friday, December 03, 2010

OK the above samples was put into the "Child" of a readonly list and not into the "parentlist". I moved that now the code looks like this now...but it still seems not te be loading the var into the serialization string.

 

    Protected Overrides Sub OnGetState(ByVal info As Csla.Serialization.Mobile.SerializationInfo)

      MyBase.OnGetState(info)

      info.AddValue("MyApp.MenuListItem._Descrip", _Descrip)

    End Sub

    Protected Overrides Sub OnSetState(ByVal info As Csla.Serialization.Mobile.SerializationInfo)

      _Descrip = info.GetValue(Of String)("MyApp.MenuListItem._Descrip")

      MyBase.OnSetState(info)

    End Sub

pgroenenstein replied on Friday, December 03, 2010

Can anyone help?...PLEASE!!

 

 

RockfordLhotka replied on Friday, December 03, 2010

The recommended solution is to have a parent object above the list that contains extra properties.

pgroenenstein replied on Friday, December 03, 2010

Thanks for the answer Rocky, I'll probably go that route.

I'm just wondering Why overriding the OnGetState and OnSetState in the readonly list does not seem to work?

Thanks

 

pgroenenstein replied on Friday, December 03, 2010

Putting a break on "OnGetState" it just never seems to get there.

RockfordLhotka replied on Friday, December 03, 2010

The base classes were created to support mainstream CSLA scenarios. There are no mainstream scenarios that support or enable the use of custom properties on lists.

Keep in mind, we basically had to re-invent serialization to get this to extend into Silverlight, but without the budget to literally recreate everything you can do with BinaryFormatter, etc. So we invented the parts necessary to meet the mainstream/core CSLA scenarios, and have slowly extended from there.

Copyright (c) Marimer LLC