locked
WCF Data Services Custom Expand RRS feed

  • Question

  • Hi everybody;

     Want to know if this can be achived with WCF DataServices 5.x and EF 5.  Imagine an Order and Order_Details  relationship, I want to get an order and associated Order_Details but the latter must be filtered, for example only Order_Details with Qty > 5

    If I do the following query using WCF:

    from o in Orders.Expand("Order_Details")
    where o.id == 10 && o.Order_Details.Any (od => od.qty > 5)
    select o

    I get Order with ID = 10, but I'm expecting to get back only 3 Order_Details, but instead of that I'm getting back the WHOLE collection of Order_Details instead of just the ones with qty > 5.

    I've also tried to build a Service Operation at the "server side" where I have more control about how to form my query, but when making the call the result is the same, I always get the WHOLE collection instead of just the subset.

    It seems  that "Expand" has no way to filter my results.

    Any help is appreciated.

    Regards,

      Enrique.


    Enrique Carbonell

    Sunday, December 23, 2012 1:37 AM

All replies

  • Hi,

    OData doesn't have a way to filter expanded sets. So there's no way to do this from the client.

    I'm not sure why it doesn't work using the server operation. I'm pretty sure it would work with reflection provider, so this is probably something EF related.

    Thanks,


    Vitek Karas [MSFT]

    Sunday, December 23, 2012 8:55 AM
    Moderator
  • Hi,

      Thanks for your answer, the problem with the "server-side" operation is that I'm beiong able to build this "custom" order with a filtered collection of "Order Details", but I don't know how to get the full object back to the "client-side". I'm calling my service operation with something like:

    Order = context.Execute<Order> (new Uri ("GetFilteredOrder?Order_Id=8", UriKind.Relative))

    in this case, the Order is comming back but it's navigation property "Order_Details" is null, I'm pretty sure the "Order_Details" collection is being correctly filtered on the "server-side", I even made a test, clearing the collection and manully adding just 1 "Order_Detail", in both cases; the object returned from the service operation call had a null "Order_Details" navigation property. The only way to get  the navigation property filled with data was calling the service operation with the "$expand" option but in this case the "Order_Details" collection was returned with the WHOLE collection instead of just the filtered result set.

    Is there a special way to query the WCF Data Service so we can get back the entity(object) needed with all it's navigation properties (either single or collection) filled in advanced?

    In my case, I would like to get back my order with it's "Customer" property filled and it's filtered "Order_Details" filled and I have no way to achive this but calling the service with the "$expand" option, but at the expense of loosing the pre-filtered "Order_Details".

    Any help is appreciated. Regards.

    Enrique.


    Enrique Carbonell

    Sunday, December 23, 2012 3:24 PM
  • I understand, and the only way to get expanded data to the client is to ask for it using the $expand. The part which I'm not sure why it doesn't work is that it returns everything, not the filtered set you asked for.

    Thanks,


    Vitek Karas [MSFT]

    Sunday, December 23, 2012 7:11 PM
    Moderator