Dear All
I'm looking to create an ASP .net page which perform lots of counts on records in my database and display them as a table to the end-user. At the moment, I'm using four LINQ queries to perform the counts - these are triggered when each row in my GridView is bound (OnRowDataBound event). So you can probably imagine, I'm cycling through all the records in my database four times for each row in my table. It is likely that this ASP .net page will eventually contain 3-4 tables, all populated in this similar way.
What I'm doing seems totally inefficient and I imagine isn't doing my SQL database a lot of good. What is the 'best practice' approach when you need to perform a lot of counts on rows in a database based on different criteria? How is it best to do it? Although I'm using a GridView at the moment to display the data, it doesn't have to be -- I'm happy to use something else if you think it is better...
Dim TotalObservationsThisYear = From Observation In db.Observations _
Where Observation.observationDate >= ReportDateFrom _
And Observation.observationDate <= ReportDateTo _
And Observation.observationPublished IsNot Nothing _
And Observation.observationSubjectLevel = observationSubjectLevel.Text _
Select Observation.observationID
Return TotalObservationsThisYear.Count
Dim TotalObservationsEver = From Observation In db.Observations _
Where Observation.observationPublished IsNot Nothing _
And Observation.observationSubjectLevel = observationSubjectLevel.Text _
Select Observation.observationID
Return TotalObservationsEver.Count
Dim CountObservationsThisYear = From Observation In db.Observations _
Where Observation.observationDate >= ReportDateFrom _
And Observation.observationDate <= ReportDateTo _
And Observation.observationOverallGrade = observationOverallGrade _
And Observation.observationPublished IsNot Nothing _
And Observation.observationSubjectLevel = observationSubjectLevel.Text _
Select Observation.observationID
Return CountObservationsThisYear.Count
Dim CountObservationsEver = From Observation In db.Observations _
Where Observation.observationPublished IsNot Nothing _
And Observation.observationOverallGrade = observationOverallGrade _
And Observation.observationSubjectLevel = observationSubjectLevel.Text _
Select Observation.observationID
Return CountObservationsEver.Count
I'd really appreciate your help/advice on this.
Many thanks
Daniel