【发布时间】:2013-12-06 13:15:31
【问题描述】:
我很难让它发挥作用。我正在尝试在 IQueryable 上使用以下过滤器助手进行半径搜索。在 RadiusSearch 应用之前,还有一组其他过滤器会被应用。顺序并不重要,因为目标是让查询延迟到 ToList() 操作。
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。
-
您是否检查过 EF 中的空间类型支持? msdn.microsoft.com/en-us/data/hh859721.aspx
标签: c# sql linq entity-framework linq-to-entities