2013-07-14 165 views
-4

這裏是我的sql查詢我想將它轉換成Lambda表達式提前轉換SQL查詢到lambda表達式

Select P.PlaceName As UnitNumber, 
     PB.PlaceName, 
     A.Locality, 
     A.SubLocality, 
     A.Sublocality_Level_1 
from Listing L 
inner join Place P ON L.PlaceId = P.Id 
Inner Join Place PB ON PB.Id = P.ParentPlaceId 
Inner Join [Address] A ON A.Id = PB.AddressId 
Where L.Id =9 

感謝。

+0

別人如何將其轉換爲Lambda表達式不知道你的對象及其屬性等?至少發佈你的班級結構,並告訴我們你已經嘗試了什麼,以及你正在面對的錯誤。如果你需要關於搜索谷歌的Lamda表達式的教程 – Ehsan

回答

0

在這種情況下查詢表達式要簡單得多。我不建議你使用lambda表達式與許多加入

from l in db.Listing 
join p in db.Place on l.PlaceId equals p.Id 
join pb in db.Place on p.ParentPlaceId equals pb.Id 
join a in db.Address on pb.AddressId equals a.Id 
where l.Id == 9 
select new { 
    UnitNumber = p.PlaceName, 
    pb.PlaceName, 
    a.Locality, 
    a.SubLocality, 
    a.Sublocality_Level_1 
} 

db是您的上下文