title: Returning view model from OData web api with EF
body: <p>I'm attempting to return a custom view model from an ODataController.  Here is the view model:</p>
  
  <pre><code>public class TaskViewModel
  {
      public int TaskID { get; set; }
      public string Name { get; set;}
      public string Details { get; set; }
      public DateTime? DueDate { get; set; }
      public virtual Project Project { get; set; }
  }
  </code></pre>
  
  <p>My controller looks like this:</p>
  
  <pre><code>public IEnumerable&lt;TaskViewModel&gt; Get(ODataQueryOptions&lt;TaskViewModel&gt; options)
  {
      IEnumerable&lt;Task&gt; tasks = db.Tasks.AsEnumerable();
      ...
      var vm = from t in tasks
               select new TaskViewModel
               {
                   TaskID = t.TaskID,
                   Name = t.Name,
                   Details = t.Details,
                   DueDate = t.DueDate,
                   Project = t.Project
               }
      return vm.AsEnumerable();
  }
  </code></pre>
  
  <p>The Task entity looks like this (generated from database-first EDMX):</p>
  
  <pre><code>public partial class Task
  {
      public int TaskID { get; set; }
      public string Name { get; set; }
      public string Details { get; set; }
      public DateTime? DueDate { get; set; }
      ... //other properties I don't want exposed
      public virtual Project Project { get; set; }
  }
  </code></pre>
  
  <p>When I attempt to perform a GET, I receive the following message:</p>
  
  <p>"No NavigationLink factory was found for the navigation property 'Project' from entity type 'MyApplication.ViewModels.TaskViewModel' on entity set 'Tasks'.  Try calling HasNavigationPropertyLink on the EntitySetConfiguration."</p>
  
  <p>Here is my WebApiConfig.cs:</p>
  
  <pre><code>builder.EntitySet&lt;Project&gt;("Projects").EntityType.HasKey(p =&gt; p.ProjectID);
  builder.EntitySet&lt;Task&gt;("Tasks").EntityType.HasKey(t =&gt; t.TaskID);
  ...
  builder.EntitySet&lt;ViewModels.TaskViewModel&gt;("TaskViewModel");
  </code></pre>
  
  <p>I've successfully done this with another entity in the application (Project), so I don't know why this one isn't working.  The only difference is the Task entity references the Project entity.</p>
  
  <p>Any help/insight is appreciated.</p>