I’ve a semi complex LINQ query that is running very slow. I do not believe it is using sub queries. I’ve tried to use logging and only see one query generated. the code is similar to the following:
dc.defferedloadingenabled = false
dc.objecttrackingenabled = false
dataloadoptions dlo = new dataloadoptions
dlo.loadwith<MyQuestion>(q => q.lotsofresponses)
dc.LoadOptions = dlo
IQuerayable<Question> questions = dc.questions.where( q => q.ParentId == specificID).orderBy(q => q.Rank);
foreach (question in questions)
{
}
Need help on how to speed this up. I believe I’m using the best practices.
Below is the SQL generated. I removed the actual key and column names. The count(*) looks odd to me.
SELECT [t0].[QId], [t0].[SId], [t0].[Tp], [t0].[St], [t0].[OL], [t0].[Is], [t0].[Tbl], [t0].[IsL], [t0].[Priority], [t1].[ResponseId], [t1].[QId] AS [QId2], [t1].[UId], [t1].[AN], [t1].[AT], (
SELECT COUNT(*)
FROM [dbo].[Responses] AS [t2]
WHERE [t2].[QId] = [t0].[QId]
) AS [value]
FROM [dbo].[Questions] AS [t0]
LEFT OUTER JOIN [dbo].[Responses] AS [t1] ON [t1].[QuestionId] = [t0].[QuestionId]
WHERE [t0].[SurveyId] = @p0
ORDER BY [t0].[Priority], [t0].[QId], [t1].[ResponseId]
Since you’ve captured the query by logging, take it to SqlStudio and examine the execution plan.
Also, run the query with
and check the messages tab for performance metrics.