2012-06-29 95 views
1

我想這個SQL查詢L2S轉換..轉換這個SQL查詢的LINQ to SQL

SELECT TOP 5 vt.* 
FROM dbo.ADTEXP_RateDefinitions vt 
    JOIN 
     (SELECT vLocationID FROM dbo.Vessel_Table WHERE iOwner=401) V 
    ON vt.VesselID=V.vLocationID 
ORDER BY vt.RateAddedDate DESC 

任何幫助或建議表示讚賞 感謝

回答

1

試試這個。

var result = (from vt in dbo.ADTEXP_RateDefinitions 
    join V in (
     (from VT1 in dbo.Vessel_Table 
     where 
      VT1.iOwner==401 
     select new { 
      VT1.vLocationID 
     })) on vt.VesselID equals V.vLocationID 
    orderby 
     vt.RateAddedDate descending 
    select vt).Take(5) 
+0

感謝隊友......我試過這個,它爲我工作.. –

0
(from vrt in _db.ADTEXP_RateDefinitions 
join vt in _db.Vessel_table 
on vrt.VesselId equals vt.locationId 
where vt.iOwner == 401 
select new 
{ 
    VesselId = vrt.VesselId, 
    Owner = vt.iOwner 
}).Take(5) 
0

我覺得它像即:

(from vt in dbo.ADTEXP_RateDefinitions 
from v in (from vlt on dbo.Vessel_Table where vlt.iOwner=401 select vlt) 
where vt.VesselID = v.vLocationID 
orderby vt.RateAddedDate descending 
select vt).Take(5); 
+0

你不能檢查像這樣的iOwner值 –