dynamics-crmodatamicrosoft-odata

Microsoft.OData.Client $expand does not populate the model


I am using Microsoft.OData.Client based on the microsoft sample application.
Here's my simple WebAPI Controller:

    [Route("test")]
    [HttpGet]
    public IHttpActionResult Test()
    {
        var context = _dynamicsContextFactory.CreateContext();
        // adding this had no effect // context.MergeOption = MergeOption.AppendOnly;
        // adding this had no effect // context.MergeOption = MergeOption.OverwriteChanges;
        // adding this had no effect // context.MergeOption = MergeOption.NoTracking;
        // adding this had no effect // context.MergeOption = MergeOption.PreserveChanges;
        var result = context.SalesOrderHeadersV2.Expand("SalesOrderLines").Take(1).ToList();
        return Ok(result);
    }

The client generates the correct URL. https://example.com/data/SalesOrderHeadersV2?$top=1&$expand=SalesOrderLines I can see in fiddler the SalesOrderLines property returned in the JSON.

However when I inspect the result variable (or view the output) there is no SalesOrderLines property. So the order lines have not been mapped into my result object from the data downloaded from the oData source.

Important Note: I am using EDMXTrimmer to reduce the number of entities in my client, could this be an issue If I’m missing a joining entity? (It seems unlikely there's a joining entity in this case)

Clue?
When I try to change this line:

var result = context.SalesOrderHeadersV2.Expand(x=>x.SalesOrderLines).Take(1).ToList();

It will not compile because 'SalesOrderHeaderV2' does not contain a definition for 'SalesOrderLines' ...
Note: context.SalesOrderLines does exist.


Solution

  • The issue was that EDMXTrimmer removed the navigation properties.
    EDMXTrimmer has since been fixed.