Any advice on how to get a SQL query similar to the following using
linq.

select      Competitions.Id,
            Competitions.Name,
            COUNT(Contestants.Id) as Entries,
            SUM(CASE WHEN Contestants.Gender = 'male' THEN 1 ELSE 0
END) as Males,
            SUM(CASE WHEN Contestants.Gender = 'female' THEN 1 ELSE 0
END) as Females
from        Competitions
inner join  Contestants
                on Competitions.Id = Contestants.CompetitionFk
group by    Competitions.Id,
            Competitions.Name

Currently using:
using(new UnitOfWorkScope())
            {
               return _competitionRepository
                    .Select(x=>new
                                   CompetitionReportDTO{
                                       Id=x.Id,
                                       Name=x.Name,
                                       StartDate=x.StartDate,
                                       EndDate=x.EndDate,
                                       TargetEntries=x.TargetEntries,
                                       State=x.State,
 
ActualEntries=x.Contestants.Count,
 
Males=x.Contestants.Where(y=>y.Gender=="male").Count(),
 
Females=x.Contestants.Where(y=>y.Gender=="female").Count()
                                   })
                    .ToList();
            }
Getting a really message query with nested queries.

Any advice really appreciated

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to