我有这个 LINQ 查询,它返回大量路线的数据和坐标。当坐标数量超过特定值时,我想排除以下路线的坐标。
这是我尝试执行此操作的方法,问题是当我尝试序列化对象时,JSON.net 序列化超时。
public static object returnFullSelectWithCoordinates(IQueryable<RouteQueryModel> r)
{
int totalCoordinateCount = 0;
foreach (route x in r.Select(c => c.b))
{
if (totalCoordinateCount > DataValues.AmountOfCoordinates)
{
x.coordinates.Clear();
}
else
{
totalCoordinateCount += x.coordinates.Count;
if (totalCoordinateCount > DataValues.AmountOfCoordinates)
{
x.coordinates.Clear();
}
}
}
return r.Select(b => new
{
route_id = b.b.route_id,
name = b.b.name,
description = b.b.description,
distance = b.b.distance,
distance_to_route = (int)b.distance_to_from_me,
departure_place = b.b.departure_place,
arrival_place = b.b.arrival_place,
owner = b.b.user.username,
average_rating = b.avg_rating,
is_favorite = b.is_favorite,
date = b.b.date,
attributes = b.b.route_attributes.Select(c => c.route_attribute_types.attribute_name),
coordinates = b.b.coordinates.Select(c => new coordinateToSend { sequence = c.sequence, lat = c.position.Latitude, lon = c.position.Longitude })
});
}