title: Spatial Linq query with distance() method
body: <p>I'm trying to get locations from a SQL Server database which are inside specific radius. It works fine when I use spatial data from database and pass it to the <code>DBGeography.Distance()</code> method. But when i try to pass coordinates to <code>Distance()</code> method like:</p>
  
  <pre><code>var sourcePoint = string.Format("POINT({0} {1})", location.lat.ToString().Replace(',','.'), location.lon.ToString().Replace(',','.'));
  
  var origin = DbGeography.PointFromText(sourcePoint, 4326);
  
  var result = from r in db.Locations
          where r.Coordinates.Distance(origin) &lt;= distanceMeters
          select r;
  </code></pre>
  
  <p>It returns nothing. Although locations are inside defined radius.</p>
  
  <p>Doing it like this works just fine and able to get locations inside radius:</p>
  
  <pre><code>var person = db.People.Single(p =&gt; p.PersonID == 2);           
  
  var stores = from s in db.Stores
           where s.Location.Distance(person.Address) * .00062 &lt;= 1
  
           select new Location
           {
  
           Name = s.Name,
           Latitude = s.Location.Latitude,
           Longitude = s.Location.Longitude
           };
  </code></pre>
  
  <p>I cant wrap my head around why it doesn't work in first example way. :)</p>