Difference in performance linq2sql sub query vs group by

peaceee

New Member
I have a linq query that is pulling a lot of data but sometimes it times out due to the load it puts on the sql server. I am going to work on getting more efficient data (adding indexes etc) but I have also heard that using a group by would be more efficient than using the sub query. Would a group by be more efficient and if so what would my query below look like with a group by? I am not familiar with group by yet.\[code\]var zips = (from s in db.ZipCodeServiceAvailabilities join b in db.ZipCodeBoundaries on s.ZipCode equals b.ZipCode where (s.IsServiced == service && b.Ordering % 10 == 0 && s.State.Contains(state)) orderby b.ZipCode select new { zipCode = b.ZipCode.Trim(), latitude = b.Latitude, longitude = b.Longitude, apartCount = (from a in db.pdx_apart_views where a.Zip_Code.Remove(5) == b.ZipCode select a.Apartment_complex).Count() }).ToArray();\[/code\]
 
Back
Top