-1
請幫我把這段代碼翻譯成linq查詢。轉換爲linq查詢
SELECT DISTINCT dbo.Port.PortId, dbo.Port.Name
FROM dbo.Port INNER JOIN
dbo.Charge ON dbo.Port.PortId = dbo.Charge.PortId
請幫我把這段代碼翻譯成linq查詢。轉換爲linq查詢
SELECT DISTINCT dbo.Port.PortId, dbo.Port.Name
FROM dbo.Port INNER JOIN
dbo.Charge ON dbo.Port.PortId = dbo.Charge.PortId
嘗試這樣
var q = (from tbl in yourContext.Port
join tbl1 in yourContext.Charge on tbl.PortId = tbl1.PortId
select tbl).Distinct().ToList();
或者試試這個(在lambda形式):
var query = youContext.Port //left table - outer
.Join (youContext.Charge, //right table - inner
p => p.PortId, //left table outer key selector
c => c.PortId, //right table inner key selector
(x, y) => new {x}) //result of join
.Select(x => new {x.PortId,
x.Name}) //finish selection
.Distinct(); //remove re-entry