I’m experiencing extremely slow query execution when linking records on foreign keys. For instance I have a “GraphPoint” class which holds DateTime/double pairs. This query executes in under a second for 150000 records (dummy number for value):
var data = from x in dataContext.Table1
select(new GraphPoint(x.Time, 100));
List<GraphPoint> graphPoints = new List<GraphPoint>(data);
When I try to link a second table on a foreign key the execution slows to a crawl. After an hour I gave up on this query:
var data = from x in dataContext.Table1
select(new GraphPoint(x.Time, x.Table2.First().Value));
List<GraphPoint> graphPoints = new List<GraphPoint>(data);
Why is it so slow compared to the first one?
I’ve tried using a precompiled query but that didn’t help either.
Use the DataContext.Log property to see the exact SQL that is being generated, then investigate if there is anything you can do at the database end to optimize the query performance (such as adding indexes).