我有一个LINQ,它工作正常。我的问题是:如何将其转换为Lambda表达式?将此LINQ转换为Lambda表达式?
var searchResults = from study in dataContext.Studies
join location in dataContext.Locations
on study.LocationID equals location.LocationID
join doctorLocation in dataContext.DoctorLocations
on location.LocationID equals doctorLocation.LocationID
join doctor in dataContext.Doctors
on doctorLocation.DoctorID equals doctor.DoctorID
where doctor.DoctorID == doctorId
select study;
我认为LINQ对我来说更自然(类似于SQL脚本)。但是,在这种情况下,我只是想将其转换为Lambda Expression,但我无法使其工作。
我被困在:
var searchResults = dataContext.Studies.Where(x =>
x.Location.DoctorLocations.FirstOrDefault() != null &&
x.Location.DoctorLocations.FirstOrDefault().DoctorID == doctorId);
这只适用于FirstOrDefault。由于有多个DoctorLocations,所以我不会写这个。
究竟你尝试过,不能让工作?请分享它。 –
已在原始帖子中更新。我不熟悉Lamda,所以陷入困境。 – urlreader