title: Database functions in Entity Framework could not return results
body: <p>I have implemented the same function "distancebetween" as in Nerddinner. I created an airport repository and have these methods:  </p>
  
  <pre><code>    public IQueryable&lt;AllAirports&gt; ReturnAllAirportWithIn50milesOfAPoint(double lat, double lon)
      {
          var airports = from d in im.AllAirports
                 where DistanceBetween(lat, lon, (double)d.Lat, (double)d.Lon) &lt; 1000.00
                 select d;
          return airports;
      }
  
      [EdmFunction("AirTravelModel.Store", "DistanceBetween")]
      public static double DistanceBetween(double lat1, double long1, double lat2, double long2)
      {
          throw new NotImplementedException("Only call through LINQ expression");
      }
  </code></pre>
  
  <p>When I tested it, it shows:   </p>
  
  <blockquote>
    <p>base   {"The specified method 'Double DistanceBetween(Double, Double, Double, Double)' on the type 'AirTravelMVC3.Models.Repository.AirportRepository' cannot be translated into a LINQ to Entities
         store expression because no overload matches the passed arguments."}   System.SystemException {System.NotSupportedException}</p>
  </blockquote>
  
  <p>Do you have any ideas on why this happen? The only different between my work and nerddinner is that I used a POCO plugin in entity framework.</p>
  
  <p>The SQL UDF is as follows, it works very well in the database:</p>
  
  <pre>
  CREATE FUNCTION [dbo].[DistanceBetween](@Lat1 as real,
  @Long1 as real, @Lat2 as real, @Long2 as real)
  RETURNS real
  AS
  BEGIN
  
  DECLARE @dLat1InRad as float(53);
  SET @dLat1InRad = @Lat1 * (PI()/180.0);
  DECLARE @dLong1InRad as float(53);
  SET @dLong1InRad = @Long1 * (PI()/180.0);
  DECLARE @dLat2InRad as float(53);
  SET @dLat2InRad = @Lat2 * (PI()/180.0);
  DECLARE @dLong2InRad as float(53);
  SET @dLong2InRad = @Long2 * (PI()/180.0);
  
  DECLARE @dLongitude as float(53);
  SET @dLongitude = @dLong2InRad - @dLong1InRad;
  DECLARE @dLatitude as float(53);
  SET @dLatitude = @dLat2InRad - @dLat1InRad;
  /* Intermediate result a. */
  DECLARE @a as float(53);
  SET @a = SQUARE (SIN (@dLatitude / 2.0)) + COS (@dLat1InRad)
  * COS (@dLat2InRad)
  * SQUARE(SIN (@dLongitude / 2.0));
  /* Intermediate result c (great circle distance in Radians). */
  DECLARE @c as real;
  SET @c = 2.0 * ATN2 (SQRT (@a), SQRT (1.0 - @a));
  DECLARE @kEarthRadius as real;
  /* SET kEarthRadius = 3956.0 miles */
  SET @kEarthRadius = 6376.5;        /* kms */
  
  DECLARE @dDistance as real;
  SET @dDistance = @kEarthRadius * @c;
  return (@dDistance);
  END
   </pre>