2016-04-18 108 views
-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 

回答

2

尝试这样

var q = (from tbl in yourContext.Port 
join tbl1 in yourContext.Charge on tbl.PortId = tbl1.PortId 
select tbl).Distinct().ToList(); 
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