I wonder if someone can help me with this. I have a LINQ query – no problems with it, but it takes far too long to return data
var result = Context.paf_wgs84.Where(c => c.Postcode.Contains(postcode)).Take(15);
Very simple, the idea as the user is typing, using AJAX, it returns a set of 15 possible matches.
The problem is, there are 1.6 million records
Running the following code in management studio takes around 3 seconds
SELECT code
FROM paf_wgs84
WHERE (code LIKE '%EC1%')
where as running the following code takes less than a second
SELECT TOP 15 code
FROM paf_wgs84
WHERE (code LIKE '%EC1%')
Is there a way of doing something similar in LINQ without using .take()?
You can try something like this. This will only return one column.
The generated Sql statement will look like this.