locked
Projection ($select) on ResourceTypes that have IsMediaLinkEntry=true. Bug? RRS feed

  • Question

  • Hi,

    I am writing a custom query provider on top of our data access layer to expose our data model thru OData.

    I have a resource type (lets call it Document) that has a number of simple properties and a stream (IsMedialLinkEntry=true).

    When I query the ResourceSet (Documents) of this type with a projection, like: /Documents?$select=SomeSimpleProperty, the projection is removed from the expression that i recieve in my provider.

    This forces my to return everything from our data store - by OData specification resulting in poor performance. The response to the client is however correct and only includes the property SomeSimpleProperty. Please note that the expression do include the projection on all other ResourceTypes than the ones that has IsMediaLinkEntry=true.

    Is this a bug or am I doing something wrong?

    I am currently on the March 2011 CTP2 release of WCF DataServices.

    Tuesday, January 10, 2012 6:57 AM

Answers

  • Hi,

    This is a known limitation of the current WCF DS. The reason for this is that the IDataServiceStreamProvider APIs take an instance of the resource to get the default stream. But if we would include projections in the query we would not get the resource instance, instead we would only get ProjectedWrapper. So we would not have the resource instance to pass to the IDataServiceStreamProvider APIs which we need to be able to serialize the entity (we need to get the read link of the default stream to put it into the atom:content/@src, in ATOM, or __metadata/media_src in JSON).

    Thanks,


    Vitek Karas [MSFT]
    • Marked as answer by Uffe Lauesen Tuesday, January 10, 2012 6:19 PM
    Tuesday, January 10, 2012 9:36 AM
    Moderator
  • Hi,

    It's just not technically possible. If we need the full instance for the stream provider, then we need to run the query without projections (obviously). Then it makes no sense to run it again with projections for serialization purposes, since we can perform the projection in our serializers from the full instance easily (that's what happens today).

    I don't understand how would we run a projection query, but still pass full instance to the stream provider.

    Thanks,


    Vitek Karas [MSFT]
    • Marked as answer by Uffe Lauesen Tuesday, January 10, 2012 6:19 PM
    Tuesday, January 10, 2012 4:18 PM
    Moderator
  • Hi Vitek,

    I was thinking if I some how could detect this in my query provider/vistor and minimize my DB select in this case. 

    Since I am writting our own provider and I have the full control of the metadata model I think the best solution for us is to simply model/move the stream to a new entity that do not have any additional properties and then have a reference to the new entity from the original.

    Thanks for the clarification.

    Regards

    Uffe

    • Marked as answer by Uffe Lauesen Tuesday, January 10, 2012 6:20 PM
    Tuesday, January 10, 2012 6:19 PM

All replies

  • Hi,

    This is a known limitation of the current WCF DS. The reason for this is that the IDataServiceStreamProvider APIs take an instance of the resource to get the default stream. But if we would include projections in the query we would not get the resource instance, instead we would only get ProjectedWrapper. So we would not have the resource instance to pass to the IDataServiceStreamProvider APIs which we need to be able to serialize the entity (we need to get the read link of the default stream to put it into the atom:content/@src, in ATOM, or __metadata/media_src in JSON).

    Thanks,


    Vitek Karas [MSFT]
    • Marked as answer by Uffe Lauesen Tuesday, January 10, 2012 6:19 PM
    Tuesday, January 10, 2012 9:36 AM
    Moderator
  • Hi,

    I see. Would it be possible to hook into the pipeline and override this behaviour (but still supply the real resource type to the steam provider)?

    Thanks for the quick response.

    Uffe

    Tuesday, January 10, 2012 10:02 AM
  • Hi,

    It's just not technically possible. If we need the full instance for the stream provider, then we need to run the query without projections (obviously). Then it makes no sense to run it again with projections for serialization purposes, since we can perform the projection in our serializers from the full instance easily (that's what happens today).

    I don't understand how would we run a projection query, but still pass full instance to the stream provider.

    Thanks,


    Vitek Karas [MSFT]
    • Marked as answer by Uffe Lauesen Tuesday, January 10, 2012 6:19 PM
    Tuesday, January 10, 2012 4:18 PM
    Moderator
  • Hi Vitek,

    I was thinking if I some how could detect this in my query provider/vistor and minimize my DB select in this case. 

    Since I am writting our own provider and I have the full control of the metadata model I think the best solution for us is to simply model/move the stream to a new entity that do not have any additional properties and then have a reference to the new entity from the original.

    Thanks for the clarification.

    Regards

    Uffe

    • Marked as answer by Uffe Lauesen Tuesday, January 10, 2012 6:20 PM
    Tuesday, January 10, 2012 6:19 PM