最好是这样做一个连接的查询:
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();
或者这样做很容易做到这一点(使用空检查):
var employer = (from person in db.People where person.PersonID == idPerson select person).FirstOrDefault().Employer;
显然,在这个中我实际上必须在2个语句中进行以进行空检查.
这里有可读性或性能问题的最佳实践吗?
我用这个:
var employer = (from person in db.People where person.PersonID == idPerson select person.Employer).FirstOrDefault();
它有第一个版本的简单,但仍然只获取数据为雇主(而不是人与用人单位).