我有一個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