请帮我把这段代码翻译成linq查询。
SELECT DISTINCT dbo.Port.PortId, dbo.Port.Name
FROM dbo.Port INNER JOIN
dbo.Charge ON dbo.Port.PortId = dbo.Charge.PortId
答案 0 :(得分:2)
试试这个
var q = (from tbl in yourContext.Port
join tbl1 in yourContext.Charge on tbl.PortId = tbl1.PortId
select tbl).Distinct().ToList();
答案 1 :(得分:0)
或试试这个(以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