Nerddinner と同じ "distance between" 関数を実装しました。私は空港リポジトリを作成し、これらのメソッドを持っています:
public IQueryable<AllAirports> ReturnAllAirportWithIn50milesOfAPoint(double lat, double lon)
{
var airports = from d in im.AllAirports
where DistanceBetween(lat, lon, (double)d.Lat, (double)d.Lon) < 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");
}
テストしたところ、次のように表示されました。
base {"型 'AirTravelMVC3.Models.Repository.AirportRepository' の指定されたメソッド 'Double DistanceBetween(Double, Double, Double, Double)' は、渡された引数に一致するオーバーロードがないため、LINQ to Entities ストア式に変換できません。" } System.SystemException {System.NotSupportedException}
なぜこれが起こるのかについて何か考えはありますか?私の作品と nerddinner の唯一の違いは、エンティティ フレームワークで POCO プラグインを使用したことです。
SQL UDF は次のとおりです。データベースで非常にうまく機能します。
CREATE FUNCTION [dbo].[DistanceBetween](@Lat1 を実数として、 @Long1 は実数、@Lat2 は実数、@Long2 は実数) 実数を返します なので 始める DECLARE @dLat1InRad as float(53); SET @dLat1InRad = @Lat1 * (PI()/180.0); @dLong1InRad を float(53) として宣言します。 SET @dLong1InRad = @Long1 * (PI()/180.0); DECLARE @dLat2InRad as float(53); SET @dLat2InRad = @Lat2 * (PI()/180.0); @dLong2InRad を 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; /* 中間結果 a. */ DECLARE @a as float(53); SET @a = SQUARE (SIN (@dLatitude / 2.0)) + COS (@dLat1InRad) * COS (@dLat2InRad) * SQUARE(SIN (@dLongitude / 2.0)); /* 中間結果 c (ラジアンでの大円距離)。*/ @c を実数として宣言します。 SET @c = 2.0 * ATN2 (SQRT (@a), SQRT (1.0 - @a)); @kEarthRadius を実数として宣言します。 /* kEarthRadius を設定 = 3956.0 マイル */ SET @kEarthRadius = 6376.5; /* キロ数 */ @dDistance を実数として宣言します。 SET @dDistance = @kEarthRadius * @c; 戻ります (@dDistance); 終わり