I'm trying to display the results of a query, the difficulty is that each row in the table will include one Route object and a list of Visit objects. I want to save the query results in a list of RouteViewModels:
public class RouteViewModel
{
public Route Route { get; set; }
public List<Visit> Visits { get; set; }
}
I run the query and try to save the results:
var query =
from r in db.Routes
join v in visitList on r equals v.Route into visits
select new { RouteObject = r, VisitList = visits };
int i = 0;
foreach (var prodGroup in query)
{
vm[i].Route = prodGroup.RouteObject; //vm is an list of RouteViewModels.
j = 0;
foreach(var prodItem in prodGroup.VisitList)
{
vm[i].Visits[j] = prodItem;
j++;
}
i++;
}
I wrote the foreach loop following answers to similar posts, but that line gives me the error:
Unable to create a constant value of type 'ApplicationDatabase.Visit'. Only primitive types or enumeration types are supported in this context
How do I access the Route and its list of Visits?