This question is continuation from: Can't think of query that solves this many to many
This LINQ query is recommended to me by user @juharr, i just added string concatenation in purpose of grouping first and last name into full name.
var courseViews = from c in db.Courses
select new CourseView()
{
CourseID = c.ID,
ProfessorName = (from l in c.Leturers
where l.Is_Professor
select l.LastName+" "+l.FirstName).FirstOrDefault(),
AssistantNames = (from l in c.Leturers
where !l.Is_Professor
select l.LastName+" "+l.FirstName)
.ToList() //hmmm problem
};
ModelView that i used is another possible cause of problems:
public class CourseView
{
public int ID { get; set; }
public string CourseName { get; set; }
public string ProfessorName { get; set; }
public List AssistantNames { get; set; }
}
Hmm List of strings for Assistant names problematic isn't it?
At the end of my stupidity, in View i looped through this list with @foreach(var s in item.AssistantNames){@s}
@Ladislav suggested using IQueryable instead of string,how where?
For solution that i made so far i get following error:
LINQ to Entities does not recognize the method 'System.Collections.Generic.List1[System.String] ToList[String](System.Collections.Generic.IEnumerable1[System.String])' method, and this method cannot be translated into a store expression.
Need help!
public List AssistantNames { get; set; }could bepublic List<string> AssistantNames { get; set; }