Is is better to do a joined query like this:
var employer = (from person in db.People join employer in db.Employers on person.EmployerID equals employer.EmployerID where person.PersonID == idPerson select employer).FirstOrDefault();
Or is it just as good to do the easy thing and do this (with null checks):
var employer = (from person in db.People where person.PersonID == idPerson select person).FirstOrDefault().Employer;
Obviously, in this one I would actually have to do it in 2 statements to get in the null check.
Is there any sort of best practice here for either readability or performance issues?
I’d use this:
It’s got the simplicity of the first version but still only fetches the data for the employer (rather than the person and the employer).