I have the following linq request ...
public List<UserProject> 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<UserProject>(); }
and I have the following view object that I am trying to populate ....
public class UserProject { UserProject() { Messages = new EnumerableQuery<Message>(); } public int ProjectId; public int UserId; public string ProjectName; public string ProjectDescription; public IEnumerable<Message> Messages;
The project may have 0 or messages. My goal here is to pass a list of UserProjects into my MVC view, each UserProject can have a collection of messages. The error I am getting is as follows
Error 1 Instance argument: cannot convert from ' System.Linq.IQueryable<AnonymousType#1>
' to ' System.Collections.Generic.IEnumerable<Riebro.Services.UserProject>
'
Error 2 ' System.Linq.IQueryable<AnonymousType#1>
' does not contain a definition for ' ToList
', and the best overload method is ' System.Linq.Enumerable.ToList<TSource>(System.Collections.Generic.IEnumerable<TSource>)
' has some invalid arguments
Currently, the message object does not have navigation properties for projects ... it should ... I will add this change later ... but for now I just need to keep working.
EDIT
Currently, the linq query looks like this:
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,
and the view class is as follows:
public class UserProject { public UserProject() { Messages = new List<Message>(); } public int ProjectId; public string UserName; public int UserId; public string ProjectName; public string ProjectDescription; public List<Message> Messages;
and now I get the following error ...
Error 1: It is not possible to implicitly convert the type ' System.Collections.Generic.IEnumerable<Riebro.Message>
' to ' System.Collections.Generic.List<Riebro.Message>
'. Explicit conversion exists (are you skipping listing?)