locked
How to download part of the entity? (need only some columns...) RRS feed

  • Question

  • Let me explain my scenario, I have a data entity composed of name, description, other columns and an Image column corresponding to a binary file inserted on the database.

    Then I need the posibility of downloading only this entity without the image and then, to download only the image.
    Why is that? because there can be a lot of entries and I want to:
    1. Load all entities without "extra data added", so I can start populating the UI.
    2. Then Load the images and then I attach the images to the entities.
    3. Also, I will save the images in the issolated storage so i can avoid downloading them next time. (a image cache).

    Is it possible to do this in WCF Data Services?

    Thanks!
    Jose
    José Luis Latorre – BcnDev.Net Founder & Coordinator – http://www.bcndev.net – http://bcngeek.com
    Tuesday, January 5, 2010 12:41 PM

Answers

  • Depending on how you want to handle your binary data you have two options:

    1. If you want the binary data to be treated as any other property you can use projections (see http://blogs.msdn.com/astoriateam/archive/2009/09/01/ado-net-data-services-v1-5-ctp2-projections-overview-server.aspx). This a new feature in Data Services v2 that allows you to get only selected properties from the server.

    2. If you want to handle your binary data separately from other properties you may implement IDataServiceStreamProvider interface. Again this is a new feature in v2. It requires a bit more work than the 1. (which should work "out of the box") but may be better for you - depending on your needs. The limitation is that you can only have one BLOB per entity.

    Both of the features are also supported by the client. The first one in form of regular Linq projections, the second in form of SetSaveStream, GetReadStream methods available on DataServiceContext class.

    Pawel
    Tuesday, January 5, 2010 10:46 PM
  • Hi,

    Just to add to Pawel's comments.
    I think you want the option #2 - the BLOBs. This feature implements something called ATOM Media Link Entries, which allow you to associate a binary stream with an entity (just one stream per entity).
    When you ask for the entity you don't get the BLOB, you just get the entity and a link to the BLOB (URL). It's up to you to ask for the BLOB only when you need it. The advantage is that you can get a separate URL for just that BLOB and use it for example directly as a source for Image element in Silverlight. Or you can choose to download it first and use it any other way.

    Thanks,
    Vitek Karas [MSFT]
    Tuesday, January 5, 2010 11:04 PM
    Moderator

All replies

  • Depending on how you want to handle your binary data you have two options:

    1. If you want the binary data to be treated as any other property you can use projections (see http://blogs.msdn.com/astoriateam/archive/2009/09/01/ado-net-data-services-v1-5-ctp2-projections-overview-server.aspx). This a new feature in Data Services v2 that allows you to get only selected properties from the server.

    2. If you want to handle your binary data separately from other properties you may implement IDataServiceStreamProvider interface. Again this is a new feature in v2. It requires a bit more work than the 1. (which should work "out of the box") but may be better for you - depending on your needs. The limitation is that you can only have one BLOB per entity.

    Both of the features are also supported by the client. The first one in form of regular Linq projections, the second in form of SetSaveStream, GetReadStream methods available on DataServiceContext class.

    Pawel
    Tuesday, January 5, 2010 10:46 PM
  • Hi,

    Just to add to Pawel's comments.
    I think you want the option #2 - the BLOBs. This feature implements something called ATOM Media Link Entries, which allow you to associate a binary stream with an entity (just one stream per entity).
    When you ask for the entity you don't get the BLOB, you just get the entity and a link to the BLOB (URL). It's up to you to ask for the BLOB only when you need it. The advantage is that you can get a separate URL for just that BLOB and use it for example directly as a source for Image element in Silverlight. Or you can choose to download it first and use it any other way.

    Thanks,
    Vitek Karas [MSFT]
    Tuesday, January 5, 2010 11:04 PM
    Moderator
  • Hi,

    Thanks so much, loks like I will go for the WCF Data Services V2 (V1.5). No wonder I found nothing about it on John Papa's book or on the documentation and blogs - I will go for it as soon as it is released as I need it for a production application. Any chance you know when it will be released?

    Thanks,
    Jose
    José Luis Latorre – BcnDev.Net Founder & Coordinator – http://www.bcndev.net – http://bcngeek.com
    Thursday, January 7, 2010 9:43 AM
  • Thanks Vitek,

    I'll go definitely for the 2nd option, using blobs as I can download all the data (if it is not too much) and that will be quick if I don't get the images... later on will be getting the images, some on a background thread, others based in demand.

    Anyway I will wait for the final release, even it is a CTP, it is a "preview" and not final, subject (and very open) to changes..

    I asked Pawell but I ask you too... do you know of the estimated release data?

    Best & thanks,
    Jose
    José Luis Latorre – BcnDev.Net Founder & Coordinator – http://www.bcndev.net – http://bcngeek.com
    Thursday, January 7, 2010 9:46 AM
  • Hi,

    It should be out really soon. Please watch our blog for the announcement.
    http://blogs.msdn.com/astoriateam/

    Thanks,
    Vitek Karas [MSFT]
    Thursday, January 7, 2010 1:45 PM
    Moderator