Does anyone know how I can reproduce this SQL Query as a SubSonic Query?
SELECT PollID, AddedDate, AddedBy, QuestionText, IsCurrent, IsArchived, ArchivedDate,
(SELECT SUM(Votes) FROM sqsc_PollOptions WHERE PollID = P.PollID) AS Votes
FROM sqsc_Polls P
WHERE IsArchived = @IsArchived1 OR IsArchived = @IsArchived2
ORDER BY AddedDate DESC
I have tried using a View and a aggregate query but it returns no rows when there are no records in the sqsc_PollOptions table which will be the case when creating a new Poll record.
This is how I was querying the view:
return new Select(Aggregate.GroupBy(VwSdPollOption.Columns.PollID, "PollID"), Aggregate.GroupBy(VwSdPollOption.Columns.QuestionText, "QuestionText"), Aggregate.GroupBy(VwSdPollOption.Columns.IsCurrent, "IsCurrent"), Aggregate.Sum(VwSdPollOption.Columns.Votes, "Votes")).From(Views.VwSdPollOption).Where(VwSdPollOption.Columns.CentreName).IsEqualTo(centreName).ExecuteDataSet();
Any help would be greatly appreciated!