title: Using Entity Framework to fetch all results within a distance of N
body: <p>I've created a column in my table with the Geography type using entity framework code first. I'm calling a linq statement to fetch the first result from my table that compares the location I pass in with all locations in the table. What I want is to just return all rows that are within 20 miles or less of my location.</p>
  
  <p>Here is what I have so far.</p>
  
  <pre><code>var myLocation = DbGeography.FromText("POINT(-122.453164 37.723057)");
  
  using (var repo = new YogaSpaceRepository())
          {
              YogaSpace space = repo.FirstWithinDistance(myLocation);
          } 
  
  public YogaSpace FirstWithinDistance(DbGeography myLocation)
      {
         var yogaSpace = (from u in context.YogaSpaces
              orderby u.Location.Distance(myLocation)
              select u).FirstOrDefault();
  
          return yogaSpace;
      }
  </code></pre>