The most straight forward way to achieve this and other similair queries in Linq is to make use of Linq's set based operations (Except
, Intersect
, Union
, Distinct
). Below is an example of putting Except
to use within your query.
var drdrs = db.Doctors.Except(
(from x in db.DrPatientXrefs
join d in db.Doctors on d.DoctorId equals x.DoctorId
where x.PatientId == patientId // probably not needed...
select d)
).ToList();
I believe this should do the trick (untested), and simply your code in the process.