Nerddinnerと同じ関数 "distancebetween"を実装しました。私は空港のリポジトリを作成し、これらのメソッドを持っている:Entity Frameworkのデータベース関数が結果を返せませんでした
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");
}
私はそれをテストしたとき、それは示しています
ベース{ "指定したメソッド『ダブル間の距離(ダブル、ダブル、ダブル、ダブル』)過負荷は、渡された引数と一致しないため、タイプ「AirTravelMVC3.Models.Repository.AirportRepository」上のエンティティにLINQに ストア発現を翻訳することはできません。 "} System.SystemException {System.NotSupportedException}
これはなぜ起こるかについてのアイデアはありますか?私の仕事と奇妙な違いは、エンティティフレームワークでPOCOプラグインを使用したことだけです。
次のようにSQL UDFは、それがデータベースに非常にうまく機能し、次のとおりです。
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
「DistanceBetween()」と呼ばれるSQL Server UDFがありますか?投稿できますか? –
@ p.campbell私は自分の投稿を編集し、UDFを含めました。 – Seen