title: linq query anonymous type cannot be converted to POCO object
body: <p>I have the following linq query ...</p>
  <pre><code>public List&lt;UserProject&gt; GetProjectsByUser(int userid)
  {
      //var query =
      return (
                 from p in this.Entities.Projects
                 join c in this.Entities.Categories 
                     on p.CategoryId equals c.CategoryId
                 join u in this.Entities.Users 
                     on p.UserId equals u.UserId
                 where p.UserId == 11
                 select
                     new
                         {
                             p.ProjectId,
                             u.UserName,
                             p.UserId,
                             ProjectName = p.Name,
                             ProjectDescription = p.Description,
                             CategoryName = c.Name
                         }
                 into pcup
                 join m in this.Entities.Messages
                     on
                     pcup.ProjectId equals m.ProjectId
                     into pm
                 select
                     new {
                         pcup.ProjectId, 
                         pcup.UserId, 
                         pcup.ProjectName, 
                         pcup.ProjectDescription, 
                         Messages = pm
                     }
             ).ToList&lt;UserProject&gt;();
  }
  </code></pre>
  <p>and I have the following view object that I am trying to populate ....</p>
  <pre><code>public class UserProject
  {
      UserProject()
      {
          Messages = new EnumerableQuery&lt;Message&gt;();
      }
  
      public int ProjectId;
      public int UserId;
      public string ProjectName;
      public string ProjectDescription;
      public IEnumerable&lt;Message&gt; Messages;
      //public string UserName;
      //public string CategoryName;
      //public int CategoryId;
  }
  </code></pre>
  <p>A project may have 0 or messages on it. My goal here is to pass a list of UserProject objects to my MVC view , each UserProject object can have a collection of messages. The error I get is as follows</p>
  <blockquote>
  <p>Error 1   Instance argument: cannot convert from '<code>System.Linq.IQueryable&lt;AnonymousType#1&gt;</code>' to '<code>System.Collections.Generic.IEnumerable&lt;Riebro.Services.UserProject&gt;</code>'</p>
  <p>Error 2   '<code>System.Linq.IQueryable&lt;AnonymousType#1&gt;</code>' does not contain a definition for '<code>ToList</code>' and the best extension method overload '<code>System.Linq.Enumerable.ToList&lt;TSource&gt;(System.Collections.Generic.IEnumerable&lt;TSource&gt;)</code>' has some invalid arguments</p>
  </blockquote>
  <p>Currently the messages entity does not have a navigation property to Projects ... it should ... I will add that change later ... but at the moment I just need to keep on working.</p>
  <h1>EDIT</h1>
  <p>As it stands now the linq query looks like this ...</p>
  <pre><code>    return (
                 from p in this.Entities.Projects
                 join c in this.Entities.Categories 
                     on p.CategoryId equals c.CategoryId
                 join u in this.Entities.Users 
                     on p.UserId equals u.UserId
                 where p.UserId == userid
                 select
                     new 
                         {
                             p.ProjectId,
                             u.UserName,
                             p.UserId,
                             p.Name,
                             p.Description,
                             //CategoryName = c.Name
                         }
                     into pcup
                     join m in this.Entities.Messages
                         on
                         pcup.ProjectId equals m.ProjectId
                         into pm
                     select
                         new UserProject { 
                             ProjectId = pcup.ProjectId, 
                             UserId = pcup.UserId,  
                             ProjectName = pcup.Name, 
                             ProjectDescription = pcup.Description, 
                             Messages = pm 
                         }
             ).ToList&lt;UserProject&gt;();
  </code></pre>
  <p>and the view class looks like this ...</p>
  <pre><code>public class UserProject
  {
      public UserProject()
      {
          Messages = new List&lt;Message&gt;();
      }
  
      public int ProjectId;
      public string UserName;
      public int UserId;
      public string ProjectName;
      public string ProjectDescription;
      public List&lt;Message&gt; Messages;
      //public string CategoryName;
      //public int CategoryId;
  }
  </code></pre>
  <p>and I am now getting the following error ...</p>
  <blockquote>
  <p>Error 1   Cannot implicitly convert type '<code>System.Collections.Generic.IEnumerable&lt;Riebro.Message&gt;</code>' to '<code>System.Collections.Generic.List&lt;Riebro.Message&gt;</code>'. An explicit conversion exists (are you missing a cast?)</p>
  </blockquote>