Suppose I have a student table with tons of columns. I want the equivalent of EF
SELECT id,lastname,firstname
FROM students
WHERE coursename='Eurasian Nomads'
ORDER BY lastname,firstname
I just want a subset of the complete model Student, so I made a view model
public class StudentView{
public int ID{get;set;}
public string LastName{get;set;}
public string FirstName{get;set;}
}
and this EF code works:
List<StudentView> students=context.Students
.Where(s=>s.CourseName=="Eurasian Nomads")
.OrderBy(s=>s.LastName)
.ThenBy(s=>s.FirstName)
.Select(s=>new StudentView(){ID=s.ID,LastName=s.LastName,FirstName=s.FirstName})
.ToList();
But my question is, does the order of these articles really matter, and if so, what rules should be followed for better performance?
For example, this also works:
List<StudentView> students=context.Students
.Select(s=>new StudentView(){ID=s.ID,LastName=s.LastName,FirstName=s.FirstName})
.OrderBy(s=>s.LastName)
.ThenBy(s=>s.FirstName)
.Where(s=>s.CourseName=="Eurasian Nomads")
.ToList();
source
share