none
Databinding - when is data transferred?

    Question

  • I'm trying to turn a custom Silverlight control of mine into an Extension to add to my collection.  It's going to be an Attachment control/type, which will allow uploading/downloading of files from the database.  I'm just trying to work out the best way of doing it.

    I'm thinking about having the control bound to a Binary field, but want to know when the data is transferred from the database to the control.

    If I bind to the Binary, but don't attempt to read or display it, is the whole field still transferred from the database?  Or is it only transferred when I attempt to read or show the data?

    If it's the former, this would be very inefficient, as every time the control is shown the data would be downloaded, regardless of whether the user actually needs it downloaded.
    I suspect my control will bind to a Collection, as items other than the actual attachment data need to be stored (filename, size) - would this make any difference?

    Friday, April 20, 2012 8:19 AM

Answers

  • No, it does not.

    If I remember correctly, this is a limitation imposed by WCF RIA Services, which is used communicate entities between the client and the server. The problem boils down to the fact that the entity objects need to be modeled and a serializable object is used to communicate the data. The serializable class cannot be generated dynamically at runtime, so the properties on that class is fixed. Thus having the client ask for a subset of fields for a particular entity type is no trivial task.

    You can use the method that I described in the linked forum post (refactor you table schema so that images are loaded on demand, thus not always loaded with the main entity data) or you can create a custom WCF RIA Service that contains the subset of fields that you want to only transfer between client and server.


    Justin Anderson, LightSwitch Development Team

    • Marked as answer by ElylV Friday, April 20, 2012 9:38 AM
    Friday, April 20, 2012 9:34 AM

All replies

  • Regardless of the type of control you are making, or the fact that a control is involved at all, if an entity has a Binary property and the entity is downloaded from the server to the client, the Binary field data is also downloaded, even if no control is showing it.

    Other users have asked about this and how to circumvent this problem. Here's just one of several threads: http://social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/cd06e2d9-22a1-45c0-b12b-fec56f9c0ddc.

    If you feel strongly that the behavior can be improved, please create a suggestion/idea on the LightSwitch Connect site or vote up an existing one.


    Justin Anderson, LightSwitch Development Team

    Friday, April 20, 2012 9:06 AM
  • Wow, it's even worse than I thought... so, if I have an entity that has an Image property, and I show the ID field from that entity in a list, every picture on every item is downloaded, even if it's no displayed?

    Doesn't Lightswitch know how to only SELECT certain fields from a table, rather than transferring, essentially the entire table?

    Friday, April 20, 2012 9:11 AM
  • No, it does not.

    If I remember correctly, this is a limitation imposed by WCF RIA Services, which is used communicate entities between the client and the server. The problem boils down to the fact that the entity objects need to be modeled and a serializable object is used to communicate the data. The serializable class cannot be generated dynamically at runtime, so the properties on that class is fixed. Thus having the client ask for a subset of fields for a particular entity type is no trivial task.

    You can use the method that I described in the linked forum post (refactor you table schema so that images are loaded on demand, thus not always loaded with the main entity data) or you can create a custom WCF RIA Service that contains the subset of fields that you want to only transfer between client and server.


    Justin Anderson, LightSwitch Development Team

    • Marked as answer by ElylV Friday, April 20, 2012 9:38 AM
    Friday, April 20, 2012 9:34 AM
  • I've submitted this idea here:

    http://visualstudio.uservoice.com/forums/127959-visual-studio-lightswitch/suggestions/2785543-allow-transferring-of-partial-entity-from-datasour

    Perhaps if others feel this would be useful they can vote it up, or expand on my description of the problem in the comments.

    Friday, April 20, 2012 9:52 AM