I have a dataset on my SQL server that contains a few million Geography Points that I want to retrieve based on a grid of DBGeography rectangles I create on the client side. Basically I want to pass in a c# List of DBGeography , and my server would hand back the list of points that fit into those geometries, along with the DBGeography they fall into. I am currently querying for each individual rectangle, causing a lot of queries if my map I'm pulling is divided into a large number of tiles. Obviously the performance suffers.
I am currently using the code below.
var pointsInRectangle = (from p in MyTable.Points
where MyRectangle.Intersects(p.Location)
select p).ToList();
Question: How would I alter it to pass in a List of DBGeography Rectangles and get the corresponding data back?
MyRectangle is a DBGeography I create in C# and Location is the point geography in my SQL table. This code currently works but only for one cell at a time. I tried a few things but to no avail. Entity Framework is not my specialty, but I also wouldn't know how in straight SQL (though I'm fine using SQL if needed for a solution).
Also I tried pulling all the points (from the larger outer rectangle) to the client, and then processing on the client side to subdivide it into a grid. The performance is very slow even though the initial query is almost instant (probably because of indexes).