View Single Post
 
Old July 22nd, 2014, 11:50 AM
shabnamzangeneh shabnamzangeneh is offline
Authorized User
Points: 82, Level: 1
Points: 82, Level: 1 Points: 82, Level: 1 Points: 82, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2014
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
Default How to improve the LINQ query performance within a for loop

Hi,

I am trying to improve the speed of my application by getting rid of the LINQ queries inside my for loops (very inefficient). Do you know the best way to do it? Should I define a local IQueryable equal to the LINQ query result and then read data from that object?

Here is a piece of my code where I have loop of a LINQ query (For Each wkend ) within another for loop (For j). It is very slow.

Code:
wkendQuery = From wkendSchedule As MilestoneWeekendSchedule In eReportContext.MilestoneWeekendSchedules Where wkendSchedule.milestoneStatusID.Equals(thisMilestoneID)

For j = 0 To dgvWaterfall.Columns.Count - 1
                If wkendQuery.ToArray.Length >= 0 Then
                    For Each wkend In wkendQuery.ToArray
                        If wkend.weekendDate = dgvWaterfall.Columns(j).HeaderText Then
                                 ...
                        End if
                    next wkend
                End if
next j
Thanks very much for your help and support.

Last edited by shabnamzangeneh; July 22nd, 2014 at 11:58 AM..