title: How to access a child object using OData, WebAPI and a DTO?
body: <p>From a WebAPI controller, I am returning a list of <code>ProjectEditorDTO</code> objects from an OData request <code>/odata/ProjectEditor?$format=json&amp;$inlinecount=allpages&amp;$top=10</code>:</p>
  
  <pre><code>    [Queryable]
      public virtual IHttpActionResult Get(ODataQueryOptions&lt;Website&gt; odataQueryOptions)
      {
          var userId = UserContext.Identity.UserId;
          try
          {
              var results = odataQueryOptions.ApplyTo(_uow.Repository&lt;Website&gt;()
                  .Query()
                  .Get()
                  .Where(u =&gt; u.UserId == userId)
                  .OrderBy(o =&gt; o.WebsiteName)).Cast&lt;Website&gt;()
                  .Select(s =&gt; new ProjectEditorDTO()
                  {
                      // projection
                      WebsiteId = s.WebsiteId,
                      WebsiteGUID = s.WebsiteGUID,
                      WebsiteName = s.WebsiteName,
                      WebsiteNotes = s.WebsiteNotes,
                      DefaultContentTypeId = s.ContentType.ContentTypeId,
                      DefaultContentType = new ContentTypeDTO
                      {
                          ContentTypeId = s.ContentType.ContentTypeId,
                          Description = s.ContentType.Description
                      }
                  });
  
              var r = results.ToList();
              . . .
  </code></pre>
  
  <p>JSON Output:</p>
  
  <pre><code>{
    "odata.metadata":"http://localhost:1981/odata/$metadata#ProjectEditor","odata.count":"2","value":[
      {
        "WebsiteId":6,"WebsiteName":"Jobs","WebsiteGUID":"5252fa54-5cbc-4b7e-aa74-4fc2c5c90a6a","WebsiteNotes":"notes","DefaultContentTypeId":67
      },{
        "WebsiteId":7,"WebsiteName":"news","WebsiteGUID":"f0717700-5900-44f7-84a4-9dde9a451285","WebsiteNotes":"notes","DefaultContentTypeId":65
      }
    ]
  }
  </code></pre>
  
  <p>In the projection, I define <code>DefaultContentType</code> but it does not appear in the JSON data returned to the client, even though it is visible at the <code>.ToList()</code> point.</p>
  
  <p>I'm not trying to define a navigation property, so I should not (and can't) <code>$expand</code> it.</p>
  
  <p>I could simply define a <code>DefaultContentTypeId</code> and <code>DefaultContentTypeDescription</code> in the projection, and would solve the problem.  However, I would like to know hot to get the <code>DefaultContentType</code> object to appear in the serialized JSON object.</p>
  
  <p><strong>-- Update --</strong></p>
  
  <p>ProjectEditorDTO:</p>
  
  <pre><code>public class ProjectEditorDTO
  {
      [ForeignKey("DefaultContentTypeId")]
      public int WebsiteId { get; set; }
  
      [Required]
      [StringLength(100, MinimumLength = 3)]
      [Display(Name = "Project Name")]
      public string WebsiteName { get; set; }
  
      public string WebsiteGUID { get; set; }
      //public string WebsitePW { get; set; }
      public string WebsiteNotes { get; set; }
  
      public int DefaultContentTypeId { get; set; }
      public string DefaultContentTypeDescription { get; set; }
  
      public virtual ContentTypeDTO DefaultContentType { get; set; }
  }
  </code></pre>
  
  <p>ContentTypeDTO:</p>
  
  <pre><code>public class ContentTypeDTO
  {
      public int ContentTypeId { get; set; }
  
      [Required]
      [StringLength(100, MinimumLength=3)]
      [Display(Name="Content Type")]
      public string Description { get; set; }
  }
  </code></pre>