I am trying to create a list of aggregate data by site, using linq to entities.
the code first model has a TrialParticipant class which contains a property representing a one to many relationship StudyCentre, and an ICollection of AdverseEvents, representing a many to one relationship.
Amongst other details, I would like to know the count of AdverseEvents per StudyCentre.
The code
var returnVal =
(from participant in _db.TrialParticipants
group participant by participant.StudyCentreId into centre
select new StudyCentreStatistic
{
TotalNo = centre.Count(),
...
AdverseEventNo = centre.Sum(participant=>participant.AdverseEvents.Count)
}).ToList();
But this creates an error:
There was an error parsing the query. [ Token line number = 72,Token line offset = 4,Token in error = SELECT
Any ideas about how to do this would be much appreciated. Thank you.
If there is a navigation property
StudyCentre.Participantsyou can do: