Get distinct records using linq to entity

后端 未结 5 829
臣服心动
臣服心动 2020-12-16 11:11

Hi I\'m using linq to entity in my application. I need to get distinct records based on one column value \"Name\"

So I have a table similar like you can see below:

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-16 11:37

    Hi here is how you can select distinct records with inner join. Hope it helps

    var distinctrecords = 
    (entity.Table.Join(entity.Table2, x => x.Column, y => y.Column, (x, y) => new {x, y})
                 .Select(@t => new {@t.x.Column2, @t.y.Column3}))
                 .GroupBy(t => t.Column2)
                 .Select(g => g.FirstOrDefault());
    

提交回复
热议问题