我一直在尋找在CodePlex上的NerdDinner範例代碼,發現以下幾點:實體框架+ SqlQuery類<T> - 這是什麼代碼的目的(的NerdDinner)
public IQueryable<Dinner> FindByLocation(float latitude, float longitude)
{
List<Dinner> resultList = new List<Dinner>();
var results = db.Database.SqlQuery<Dinner>("SELECT * FROM Dinners WHERE EventDate >= {0} AND dbo.DistanceBetween({1}, {2}, Latitude, Longitude) < 1000", DateTime.Now, latitude, longitude);
foreach (Dinner result in results)
{
resultList.Add(db.Dinners.Where(d => d.DinnerID == result.DinnerID).FirstOrDefault());
}
return resultList.AsQueryable<Dinner>();
}
我很好奇這行有什麼意義是:
resultList.Add(db.Dinners.Where(d => d.DinnerID == result.DinnerID).FirstOrDefault();
代碼調用ExecuteQuery來檢索Dinners。爲什麼需要再次查詢調用FirstOrDefault()以添加到列表中?
'結果'的類型是什麼? – Dave