Silverlight 3 & Field Manager

Silverlight 3 & Field Manager

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


acgritt posted on Tuesday, July 14, 2009

We are currently looking at using Silverlight 3 because of the Out-Of-Browser support that it provides.  This means that we will have a need to save data from the business objects to the local data store.  However, after taking a look at the LocalData examples for running CSLA in Local mode for Silverlight and pulling down CSLA 3.7.0 I have found that there is some lacking functionality to support what we want to do and was wondering if there is a way to get around this. 

The normal Business Object usage is that in the DataPortal_Insert/Update or Child_Insert/Update methods is to call FieldManager.UpdateChildren passing in the extra parameters that are needed so that the child objects can then go and preform their save.  However, the FieldManager object in Silverlight does not contain this method.  Does this mean I would have to iterate over any child collections or child objects and call their BeginSave individually, or is there another, perhaps better, way to handle this?

Adam Gritt

pondosinat replied on Tuesday, July 14, 2009

If using CSLA, you would simply call Save at the root object and all your children will get updated automatically. Silverlight 3 is no exception. Have a look at the book or Rocky's videos for more info.

Post Edit - sorry- I see you're asking about the local datastore, which I am no expert on...

acgritt replied on Tuesday, July 14, 2009

I have read both the 2005 and 2008 books.  After looking through all the examples I did find the LocalDataPortalUsingWcfService to be of help but that only allowed me to call the local DataPortal_* methods.  The bigger problem is that the expected functionality for then calling to do the Child_* methods doesn't exist for client side Silverlight.  I realize this is something new that is probably going to come about with support for the new SL3 features.  I am just curious as to when these changes might be able to be expected so I can go back to the Project Manager and tell him whether or not what he wants is do-able in the time frame.

sergeyb replied on Tuesday, July 14, 2009

You can iterate through children and call DataPortal.UpdateChild for each one.  What I am not sure about in your questions is why out of browser means local data store.  Maybe I am missing a system requirement somewhere.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: acgritt [mailto:cslanet@lhotka.net]
Sent: Tuesday, July 14, 2009 1:18 PM
To: Sergey Barskiy
Subject: [CSLA .NET] Silverlight 3 & Field Manager

 

We are currently looking at using Silverlight 3 because of the Out-Of-Browser support that it provides.  This means that we will have a need to save data from the business objects to the local data store.  However, after taking a look at the LocalData examples for running CSLA in Local mode for Silverlight and pulling down CSLA 3.7.0 I have found that there is some lacking functionality to support what we want to do and was wondering if there is a way to get around this. 

The normal Business Object usage is that in the DataPortal_Insert/Update or Child_Insert/Update methods is to call FieldManager.UpdateChildren passing in the extra parameters that are needed so that the child objects can then go and preform their save.  However, the FieldManager object in Silverlight does not contain this method.  Does this mean I would have to iterate over any child collections or child objects and call their BeginSave individually, or is there another, perhaps better, way to handle this?

Adam Gritt


acgritt replied on Wednesday, July 15, 2009

My bad, what I should have said was that it needs to support working in Detached mode not Out of Browser.  We have been having so many discussions as to what our client wants that I have been getting things all jumbled in my head.  They would like to have the application support running in Out of Browser mode and support working Detached.  It is the detached that is giving us the problem in the general saving of the children.

sergeyb replied on Wednesday, July 15, 2009

In general I try to stay away from IsolatedStorage for a few reasons:

1.      It is specific to computer and computer user

2.      It has size limit

 

If you must use it (which I do not recommend), the cheapest way is to use MobileFormatter to serialize object graph and write it to isolated storage.  You will have version issues to deal with here though, as you mot be able to open those files of application version changes.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: acgritt [mailto:cslanet@lhotka.net]
Sent: Wednesday, July 15, 2009 8:10 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: Silverlight 3 & Field Manager

 

My bad, what I should have said was that it needs to support working in Detached mode not Out of Browser.  We have been having so many discussions as to what our client wants that I have been getting things all jumbled in my head.  They would like to have the application support running in Out of Browser mode and support working Detached.  It is the detached that is giving us the problem in the general saving of the children.


acgritt replied on Wednesday, July 15, 2009

We would prefer to avoid the Isolated Storage but the application we are creating should be able to handle the the two issues you brought up.  The application is a Configuration application where the old configuration systems used to be a bunch of Excel/Flatfiles and they want to move this so that the database is master instead of the files.  Part of the problem is that many of the objects support referencing other objects of the same type.  For instance Type A has children of Type B and Type B can point to other Type B's that are children of Type A.  Because of this we would have to save each time a Type B is added but they want to have the ability to add these items in an Excel like grid.  We found this can cause a performance problem trying to validate and save the changes at the proper times in order to make all the foreign key references work.  We have discussed that when we create Type A that we create the max number of each child types but this can also get rather large in a hurry because there are 6 child lists which are currently limited to a max number of items of 88 or 100.  The future plans are that this would increase which would cause a much greater load on the system to transfer these objects across the wire.  We have discussed using Guid's as the PK for the records but that still has the issue of if a user adds 3 B's to the system and the first one is the one that references the other two, it is difficult to make sure that they all get saved in the proper order.  If I am doing something fundamentally wrong here architecture wise I would love to hear it.  If it would make more sense to discuss it off the forums let me know. 

However, we do plan on implementing it such that a user has to check out a configuration to work on locally so we don't have an issue with the first item and we can always request that the size of the data store be increased if we need it to be for the second one.

sergeyb:

In general I try to stay away from IsolatedStorage for a few reasons:

1.      It is specific to computer and computer user

2.      It has size limit

 

If you must use it (which I do not recommend), the cheapest way is to use MobileFormatter to serialize object graph and write it to isolated storage.  You will have version issues to deal with here though, as you mot be able to open those files of application version changes.




sergeyb replied on Wednesday, July 15, 2009

I do not see anything fundamentally wrong other then supporting version change.  You would need to check for checkouts before upgrade, that is all.  So, using IS should fine, just use MobileFormatter + ICSharpZipLib to keep the size down.  I would use GUIDS though because this is a distributed application, and anything else would be very painfull.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: acgritt [mailto:cslanet@lhotka.net]
Sent: Wednesday, July 15, 2009 8:34 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: RE: Silverlight 3 & Field Manager

 

We would prefer to avoid the Isolated Storage but the application we are creating should be able to handle the the two issues you brought up.  The application is a Configuration application where the old configuration systems used to be a bunch of Excel/Flatfiles and they want to move this so that the database is master instead of the files.  Part of the problem is that many of the objects support referencing other objects of the same type.  For instance Type A has children of Type B and Type B can point to other Type B's that are children of Type A.  Because of this we would have to save each time a Type B is added but they want to have the ability to add these items in an Excel like grid.  We found this can cause a performance problem trying to validate and save the changes at the proper times in order to make all the foreign key references work.  We have discussed that when we create Type A that we create the max number of each child types but this can also get rather large in a hurry because there are 6 child lists which are currently limited to a max number of items of 88 or 100.  The future plans are that this would increase which would cause a much greater load on the system to transfer these objects across the wire.  We have discussed using Guid's as the PK for the records but that still has the issue of if a user adds 3 B's to the system and the first one is the one that references the other two, it is difficult to make sure that they all get saved in the proper order.  If I am doing something fundamentally wrong here architecture wise I would love to hear it.  If it would make more sense to discuss it off the forums let me know. 

However, we do plan on implementing it such that a user has to check out a configuration to work on locally so we don't have an issue with the first item and we can always request that the size of the data store be increased if we need it to be for the second one.

sergeyb:

In general I try to stay away from IsolatedStorage for a few reasons:

1.      It is specific to computer and computer user

2.      It has size limit

 

If you must use it (which I do not recommend), the cheapest way is to use MobileFormatter to serialize object graph and write it to isolated storage.  You will have version issues to deal with here though, as you mot be able to open those files of application version changes.

 





acgritt replied on Wednesday, July 15, 2009

Ok, I will give this a try.  Do you have any recommendations for a better way to save the objects with the inter-dependencies?  We have been talking about a "manager" business object that would do the synchronization and would then have the intelligence to build out the object graph and save it to the server multiple times so that we can maintain a proper order of operations.  However, even this isn't going to be easy to manage.  I feel like I am missing something here that might make things go easier. 

I have been thinking about doing something similar to what the Assignment class in the ProjectTracker sample does.  However, our tables are not set up in a similar manner and we would always have to deal with saving an object to the database as part of the create for the object, which is something I think we want to avoid because it would be desired to have the user make whatever changes they want then click a single save button rather than having the UI automatically saving changes as they happen.

sergeyb replied on Wednesday, July 15, 2009

I had to do the same with self-referencing table using EF, and it is no walk in the park – a lot of manual labor.  I really do not know how to do this easier.  I setup parent id in each object in the list, and had a recursive call that takes parent ID and saves children.  The initial call had parent id = blank, so it started with top most rows.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: acgritt [mailto:cslanet@lhotka.net]
Sent: Wednesday, July 15, 2009 9:35 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: RE: RE: Silverlight 3 & Field Manager

 

Ok, I will give this a try.  Do you have any recommendations for a better way to save the objects with the inter-dependencies?  We have been talking about a "manager" business object that would do the synchronization and would then have the intelligence to build out the object graph and save it to the server multiple times so that we can maintain a proper order of operations.  However, even this isn't going to be easy to manage.  I feel like I am missing something here that might make things go easier. 

I have been thinking about doing something similar to what the Assignment class in the ProjectTracker sample does.  However, our tables are not set up in a similar manner and we would always have to deal with saving an object to the database as part of the create for the object, which is something I think we want to avoid because it would be desired to have the user make whatever changes they want then click a single save button rather than having the UI automatically saving changes as they happen.


acgritt replied on Wednesday, July 15, 2009

In that case did you save the Parent and then take the id and use that for the children as a separate SaveChanges call? Or did you use a Guid and just pass it down and do a single SaveChanges call like in the updated Rolodex sample that I believe you had created that used the Entity Framework (also a model I am trying to follow)?

sergeyb replied on Wednesday, July 15, 2009

I was just looping through the list, and just saving one row at a time.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: acgritt [mailto:cslanet@lhotka.net]
Sent: Wednesday, July 15, 2009 2:15 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: RE: RE: RE: Silverlight 3 & Field Manager

 

In that case did you save the Parent and then take the id and use that for the children as a separate SaveChanges call? Or did you use a Guid and just pass it down and do a single SaveChanges call like in the updated Rolodex sample that I believe you had created that used the Entity Framework (also a model I am trying to follow)?


acgritt replied on Thursday, July 16, 2009

I am trying to take your advice and use the MobileFormatter and ICSharpZipLib however I am wondering if I am missing something because while the data comes across the line from the web service just fine, I can't seem to get it to serialize locally without going through and adding KnownType attributes to several of the types.  I am trying to use the DataContractSerializer to serialize the objects.  I haven't been able to find much other information about the MobileFormatter and how to use it otherwise.

sergeyb replied on Thursday, July 16, 2009

Use MobileFormatter to serialize the object instead of DataContarcSerializer, the compress the output (byte[])

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: acgritt [mailto:cslanet@lhotka.net]
Sent: Thursday, July 16, 2009 11:17 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: RE: RE: RE: RE: Silverlight 3 & Field Manager

 

I am trying to take your advice and use the MobileFormatter and ICSharpZipLib however I am wondering if I am missing something because while the data comes across the line from the web service just fine, I can't seem to get it to serialize locally without going through and adding KnownType attributes to several of the types.  I am trying to use the DataContractSerializer to serialize the objects.  I haven't been able to find much other information about the MobileFormatter and how to use it otherwise.


cristoph replied on Tuesday, December 08, 2009

Is better if you use a Silverlight client side database. For example with siaqodb( http://siaqodb.com ) you can save objects into client side database very simple and get them back via LINQ. I think this is what you need...

Copyright (c) Marimer LLC