title: Compute and return distance in EF 6 / LINQ to Entities / DbGeography?
body: <p>Using <strong>.NET 4.5.1</strong> and <strong>Entity Framework 6.0.2</strong>, I've got something like the entities and query below.</p>
  
  <p>Basically I am selecting a <code>new</code> entity and mashing the <code>Distance</code> into it, when I'd rather query a <code>Person</code> and have <code>Distance</code> embedded in that person's <code>Location</code> entity.</p>
  
  <pre><code>public class Person
  {
      public string Id { get; set; }
      public string Name { get; set; }
      [...]
  
      public virtual ICollection&lt;PersonLocation&gt; PersonLocations { get; private set;}
  }
  
  public class Location
  {
      public int Id { get; set; }
      public DbGeography Geocode { get; set; }
      // ... I want calculated Distance right here 
  }
  
  public class PersonLocation
  {
      public int PersonId { get; set; }
      public int LocationId { get; set; }
      public bool AcceptingNewClients { get; set; }
      public Hours Hours { get; set; }
      [...]
  
      public virtual Person Person { get; private set; }
      public virtual Location Location { get; private set; }
  }
  </code></pre>
  
  <p>Currently I have a query like this, where <code>_geo</code> is a <code>DbGeography</code> set to the desired search location and <code>radius</code> is an <code>int = 15</code>:</p>
  
  <pre><code>IQueryable&lt;PersonWithDistance&gt; results =
      from pl in db.PersonLocations
      let distance = pl.Location.Geocode.Distance(_geo)
      where pl.Location.Geocode.IsEmpty == false
      where distance &lt;= radius * 1609.344
      orderby distance
      select new { Person = pl.Person, Distance = Math.Round((double)(distance / 1609.344), 1) };
  </code></pre>
  
  <p>What I'd like instead is to have <code>Distance</code> added to each <code>Location</code> entity and just select the <code>Person</code> entity in the query.</p>
  
  <p>Is there a way to do this?  Should I be going a different route altogether?</p>