Can I return only specific properties of nested entities when using the LINQ provider for OData? (equivalent of $expand and $select)
<p>I'm using the <a href="https://github.com/OData/odata.net/" rel="nofollow">OData .NET Client</a> against the Dynamics CRM Online Web API. I can fetch a single Account entity like this:</p>

<pre><code>var context = new DataServiceContext(new Uri("https://myorg.crm4.dynamics.com/api/data/v8.1/"));
// I hook into the BuildingRequest event here to add my auth header token
var accountID = new Guid("8d4e3373-454f-e611-80dc-c4346bad506c");

var account = (from a in context.Accounts
               where a.Accountid == accountID
               select new Account {
                   Name = a.Name,
                   Createdby = a.Createdby
               }).Single();
</code></pre>

<p>The resulting OData query string looks like this:</p>

<pre><code>https://myorg.crm4.dynamics.com/api/data/v8.1/accounts(8d4e3373-454f-e611-80dc-c4346bad506c)?$expand=createdby&amp;$select=name
</code></pre>

<p>This works fine and returns the Account with just its name. My "problem" is that it also returns the entire SystemUser entity and all of its properties and nests them in CreatedBy.</p>

<pre><code>{
"@odata.context":"https://myorg.crm4.dynamics.com/api/data/v8.1/$metadata#accounts(name,createdby)/$entity",
"@odata.etag":"W/\"752336\"",
"name":"Test Account 01",
"accountid":"8d4e3373-454f-e611-80dc-c4346bad506c",
"createdby":{
    "@odata.etag":"W/\"752039\"",
    "ownerid":"11fd590a-6147-e611-80d8-c4346bad62c0",
    "_queueid_value":"16fd590a-6147-e611-80d8-c4346bad62c0",
    "_createdby_value":null,

    ... lots of other properties here ...

    "address1_stateorprovince":null,
    "displayinserviceviews":false,
    "timezoneruleversionnumber":null
    }
}
</code></pre>

<p>I want to return only specific properties of the SystemUser entity which would use an OData query like this (the important part is <code>$expand=createdby($select=fullname)</code>):</p>

<pre><code>https://myorg.crm4.dynamics.com/api/data/v8.1/accounts(8d4e3373-454f-e611-80dc-c4346bad506c)?$expand=createdby($select=fullname)&amp;$select=name
</code></pre>

<p>If I run the above query I now get the Account entity with just its name and for CreatedBy it only has the Fullname property of the SystemUser.</p>

<p>I can't find a way to do this in the initial LINQ query. I tried this and got errors:</p>

<pre><code>var account = (from a in context.Accounts
           where a.Accountid == accountID
           select new Account {
               Name = a.Name,
               Createdby = new SystemUser { Fullname = a.Createdby.Fullname }
           }).Single();
</code></pre>

<p><strong>Is it possible to select just specific properties of nested entities rather than the whole thing?</strong><br>
It's not the end of the world to return the entire thing, I just like to return only the data I want if it can be helped.</p>

<p>Edit 17/08/2016: After some further troubleshooting it appears that creating a new SystemUser and populating only the full name property does actually generate the correct OData query string. If I run it manually I get the correct result. I still get errors running it through the OData Client model. The error is:</p>

<blockquote>
  <p>The expected property 'Createdby' could not be found while processing an entry. Check for null before accessing this property.</p>
</blockquote>

<p>The property is not null, it can't be by definition. I think it might be looking for CreatedBy on the SystemUser entity rather than on Account, but I'm not sure.</p>