title: How do I use spatials to search a radius of zip codes?
body: <p><strong>Background</strong></p>
  
  <p>I'm writing an application which finds events within a certain radius of a zip code. You can think of this like ticketmaster, where you type in your zip code and all of the concerts in the radius of x show up.</p>
  
  <p>I have a database table which has the zip code, and each zip codes' Latitude and Longitude. I also have an 'EventListings' table where each 'Event' has a ZipCode field.</p>
  
  <p><strong>Problem</strong></p>
  
  <p>Currently, I'm using the Haversine formula in a Linq-to-Entities query in my service layer to find which events are within the radius. Right now, I'm using it as a filter in the where clause. I'd also like to place it in the select clause so on the website I can show "this is 4.6 miles away", etc. </p>
  
  <p>I can't move this code into a separate C# method because Linq-to-Entities will complain that it can't convert it to sql, so that leaves me with duplicating the entire formula in the select statement too. This is very ugly. I tried to fix it.</p>
  
  <p><strong>What I've Tried</strong></p>
  
  <p>I edited the Entity, and added a special scalar property of "DistanceFromOrigin". I then created a stored procedure which brought back all the entity data, plus a hard coded value (for testing purposes) for the new field "DistanceFromOrigin".</p>
  
  <p>I then came to realize that I can't tell entity framework to use my sproc for its select statement on the EventListings entity...  Phil suggested spatials, so thats what I went with.</p>
  
  <p><strong>Question</strong></p>
  
  <p>How can I use Spatials to search for events within a radius of zip codes?</p>