I have these queries:
weathers = query.Skip(args.Skip.Value).Take(args.Top.Value).ToList<Weather>();
List<IGrouping<int, Weather>> averages = context.Weathers
.Where(w => weathers.Select(lw => lw.Date.DayOfYear).Contains(w.Date.DayOfYear))
.GroupBy(w => w.Date.DayOfYear).ToList();
the second query can't be translated, I want to group a series of weather entities by their Date's dayofyear.
There is a List of weathers that I first load (for example 10 weathers) and then go to database and for each of them load previous years (in the same day) weathers.
How to make this query to work?
CodePudding user response:
I solved my problem like this:
var averages1 = context.Weathers
.Where(w => weathers.Select(lw => lw.Date.DayOfYear).Contains(w.Date.DayOfYear))
.ToList();
averages = averages1.GroupBy(w => w.Date.DayOfYear).ToList();
it will not have a performance problem.