Let's say I have a list of Student objects and I want to find their tuition. Their tuition is in a database and the key is their student id. I want to map that tuition into the student objects after. So I have
Class Student{
int Id;
string Name;
double GPA;
double Tuition;
}
Example Database Tuple would be |Id | Tuition | SchoolName| Student Name|
List<Double> GetTuitionsById(List<Student> students)
{
var ids = students.Select(x => x.Id).ToList();
var query = from dbStudent in _context.StudentsDB
where ids.Contains(dbStudent.Id)
select dbStudent.Tuition;
var tuitions = query.ToList();
return tuitions;
}
I was then hoping to loop through tuitions and map it into the students list, but the select query doesn't return the prices in the same order. So how can I map the tuitions from the DB to the student objects?