I've been using OData for a while now and am finding it a fantastic tool for setting up my server. Today I've come across something I haven't seen before and it's absolutely confounding me.
I'm using .Expand on the client to request a tree of data for a report when it's fetched. I've used the exact query in a prototype and it worked perfectly (ie fully hydrated). When I use Fiddler to send the query the response packet is perfect and includes all of the data I'm looking for.
The problem is that none of the expanded properties have been hydrated by the client (with a service reference completely up-to-date with the current service). In order to try and work out what's going on I've narrowed the scope right back to a single property and it's still not working.
var report = (serviceContext.Reports.Expand("ReportAreas").Where(r=>r.ReportID==reportID)).SingleOrDefault();
gives me the report but ReportAreas contains 0 items. If I then try:
serviceContext.LoadProperty(report,"ReportAreas");
then ReportAreas contains 20 or so items.
It's driving me absolutely crazy because Expand is working for a different object tree (different query but same functional code) without any issues at all. Does anyone have suggestions as to how I can work out what on earth is going on here???
Update:
Some new information on this one today which is possibly wierder and suggests to me a bug in the OData client. I've discovered that only a subset of the Report objects come back without the expanded properties being populated. MOST of the reports in the database are perfectly fine. ie If I request all Reports with ReportAreas expanded (instead of refining to a single reportID) about 80-90% have a non-zero count for ReportAreas where the remainder have 0.
When a report comes back without any of the properties populated (null or 0 count) the actual property objects are being instantiated AND their properties are being set (from breakpoints in the Reference.cs file for the service reference) so, for example the ReportID, PropertyAreaID and History values belonging to ReportArea objects are set 16 times during the query resolution but the ReportAreas list has a count of 0 when it is requested. When I use _service.LoadProperty it returns 16 ReportAreas.
It smells to me of a reference mismatch in the Expand query but it is too consistent to be a simple problem. Reports that work ALWAYS work and Reports that don't work NEVER work. Really hoping someone can help me pinpoint this so I can move on to some useful coding...