我很难让这个工作。我正在尝试在IQueryable上使用以下Filter助手进行半径搜索。还有一组其他过滤器在RadiusSearch应用之前应用。顺序应该不重要,因为目标是让查询延迟到ToList()操作。在LINQ查询中调用SQL用户定义的函数
public static IQueryable<ApiSearchCommunity> RadiusSearch(this IQueryable<ApiSearchCommunity> communities)
{
var centerLatitude = 30.421278;
var centerLongitude = -97.426261;
var radius = 25;
return communities.Select(c => new ApiSearchCommunity()
{
CommunityId = c.CommunityId,
City = c.City,
//Distance = c.GetArcDistance(centerLatitude, centerLongitude, c.Latitude, c.Longitude, radius)
});
}
可不知何故,我写这样GetArcDistance一个帮手以上,后者又调用SQL上一个UDF?我试图生成查询如下
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 <= 25
ORDER BY comms.distance
您使用的是什么版本的实体框架? –
我正在使用版本5。 – Praveen
您是否检查过EF中的空间类型支持? http://msdn.microsoft.com/en-us/data/hh859721.aspx –