1
這可以重構爲一個LINQ語句嗎?我覺得它可以,但不能包裹我的頭。擴展方法和LINQ的混雜只是讓我看起來很醜。LINQ to SQL重構foreach幫助
(db是一個DataContext。)
void AddToSeries(Series series, DateTime date)
{
foreach (var date in db.Ad.Select(ad => ad.DateTime.Date).Distinct())
{
var phraseCount = (from pc in db.PhraseCount
where pc.DateTime.Date == date
select pc.Count).SingleOrDefault();
var adCount = db.Ad.Where(ad => ad.DateTime.Date == date).Count();
series.Add(new KeyValuePair<DateTime, double>(date, adCount));
}
}
phraseCount要求什麼? – 2009-10-21 12:18:40