title: Calling a SQL User-defined function in a LINQ query
body: <p>I am having a hard time getting this to work. I am trying to do a radius search using the following Filter helper on an IQueryable. There are a set of other filters that get applied before RadiusSearch applies. The order shouldn't really matter since the goal is to get the query to be deferred until a ToList() operation.</p>
  
  <pre><code>public static IQueryable&lt;ApiSearchCommunity&gt; RadiusSearch(this IQueryable&lt;ApiSearchCommunity&gt; communities)
  {
      var centerLatitude = 30.421278;
      var centerLongitude = -97.426261;
      var radius = 25;
  
      return communities.Select(c =&gt; new ApiSearchCommunity()
      {
          CommunityId = c.CommunityId,
          City = c.City,
          //Distance = c.GetArcDistance(centerLatitude, centerLongitude, c.Latitude, c.Longitude, radius)
      });
  }
  </code></pre>
  
  <p>Can I somehow write a helper like GetArcDistance above which in turn calls a UDF on SQL? The query I am trying to generate is the following</p>
  
  <pre><code>SELECT 
      comms.community_id, 
      comms.city, 
      comms.distance 
  FROM (
      SELECT 
          c.community_id, 
          c.city, 
          dbo.udf_ArcDistance(
              30.421278,-97.426261, 
              c.community_latitude,
              c.community_longitude
          ) AS distance 
      FROM communities c) AS comms 
  WHERE comms.distance &lt;= 25 
  ORDER BY comms.distance
  </code></pre>