I have a SQL table with about 380,000 rows.
In SQL SMSS I perform this query:
SELECT Longitude, Latitude, street FROM [Stops].[dbo].[Members]
WHERE ABS(Latitude - 51.463419) < 0.005 AND ABS(Longitude - 0.099) < 0.005
It returns about 20 results almost instantly.
I have a WCF webserice to expose my Data to my Windows phone application:
public class Service1 : IService1
{
double curLatitude = 51.463;
double curLongitude = 0.099;
public List<Member> GetMembers()
{
DataClassesDataContext db = new DataClassesDataContext();
var members = from member in db.Members
where (Convert.ToDouble(member.Latitude) - curLatitude) < 0.005 && (Convert.ToDouble(member.Longitude) - curLongitude) < 0.005
select member;
return members.ToList();
}
}
I beleive it is doing the same query, but also adding the items to a List.
The problem is, is that it takes 7+ minutes then I get some strange exception so never completes. The WCF service tester in VS2010 just fills up with memory and uses lots of CPU when permforming this.
My feeling is that the ToList is doing something odd?
You are missing the abs-part in your LINQ version.
Some side notes.
You can track the SQL query in at least two possible ways.
db.Log = Console.Out;(or anotherTextWriter) and check the output window in Visual Studio.You should dispose your DataClassesDataContext, the best way is to put it in a using block: