我確信這已被回答,我找不到它。總之,我有一個LINQ的聲明,我比較一GeoCoorinate與用戶輸入另一會有地理座標基地:如何捕獲在where子句中創建的Linq(方法語法)值?
var agents = db.AllAgentLocations()
.AsEnumerable()
.Where(al => al.PrimaryOffice)
.Where(al => (25 >= (searchCoords.GetDistanceTo(
new GeoCoordinate
{
Latitude = double.Parse(al.Location.Latitude),
Longitude = double.Parse(al.Location.Longitude)
}
)/1609.34)))
.Select(a => a.Agent);
查詢工作得很好,我得到一個IEnumerable的預期輸出。我想弄清楚的
(25 >= (searchCoords.GetDistanceTo(
new GeoCoordinate
{
Latitude = double.Parse(al.Location.Latitude),
Longitude = double.Parse(al.Location.Longitude)
}
)/1609.34)
我期待輸出產生的距離的方式把雙方劑(S)和距離(S)到一個IEnumerable它看起來像這樣:
public class AgentDistanceViewModel
{
public Agent Agent { get; set; }
public double Distance { get; set; }
}
完美,感謝您抽出寶貴的時間來解釋。這實際上有很大幫助。 –