2
votes

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...

1
Can you try Fiddler and see what query (URL) is send to the server and if the response contains the expanded data.Vitek Karas MSFT
As per paragraph 2 "When I use Fiddler to send the query the response packet is perfect (ie contains all of the expanded data)"Red Nightingale
I understand that when you send the request manually from Fiddler it works. I was asking if you could use Fiddler to see the request sent by the client application, especially the URL asked for and the response.Vitek Karas MSFT
Ahhh... Don't have time to check now. I'll get onto it first thing tomorrow morning.Red Nightingale
Ok, as I suspected the request and response appear to be perfectly formed. The only thing that's not happening is the objects appearing as part of the object graph. I can populate every one of the properties with service.Property( , ) but it's taking about 30 seconds.Red Nightingale

1 Answers

0
votes

The solution to this problem (at least until I understand it better) is to set

serviceContext.MergeOption = MergeOption.OverwriteChanges;

I've been told this relates to the client not rehydrating links if they're already being tracked. I'll update this answer if I find out more/understand the problem better.