How can I write a query using Entity Framework (EF) to retrieve YearResult
records with a given list of UserYearCombination
?
Sample Combinations:
UserId Year
1 2015
1 2016
1 2018
12 2016
12 2019
3 2015
91 1999
I need to use the list of UserYearCombination
values as follows:
List<UserYearCombination> userYears = GetApprovedYears();
var records = dbcontext.YearResults.Where(y => userYears.Contains(
new UserYearCombination
{
UserId = y.UserId,
Year = y.Year
}
));