WCF data services - Limiting related objects returned based on critera

Posted by Mike Morley on Stack Overflow See other posts from Stack Overflow or by Mike Morley
Published on 2010-12-28T18:45:52Z Indexed on 2010/12/31 21:53 UTC
Read the original article Hit count: 201

I have an object graph consisting of a base employee object, and a set of related message objects.

I am able to return the employee objects based on search criteria on the employee properties (eg team) etc. However, if I expand on the messages, I get the full collection of messages back. I would like to be able to either take the top n messages (i.e. restrict to 10 most recent) or ideally use a date range on the message objects to limit how many are brought back.

So far I have not been able to figure out a way of doing this: I get an error if I attempt to filter on properties on the message (&$filter=employee/message/StartDate gives an error ">No property 'StartDate' exists in type 'System.Data.Objects.DataClasses.EntityCollection`1).

Attempting to use Top on the message related object doesn't work either.

I have also tried using a WebGet extension that takes a string list of employee IDs. That works until the list gets too long, and then fails due to the URL getting too long (it might be possible to setup a paging mechanism on this approach)...

Unfortunately the UI control I am using requires the data to be in a fairly specific hierarchical shape, so I can't easily come at this from starting on the message side and working backwards.

Outside of making multiple calls does anyone know of a method to accomplish this with wcf data services?

Thanks! M.

© Stack Overflow or respective owner

Related posts about silverlight-4.0

Related posts about wcf-ria-services