如何在entityframework中获得不同的行?

时间:2015-12-29 08:24:56

标签: c# wcf entity-framework-6 entity-framework-5

如何使用entity-framework从表中获取不同的行。

就像我想要的那样,2个不同的行名称是唯一的:

1| 04-DEC-15|   01-JAN-01   |4  |1  |10000.0    |0.0    |ship   |None   |LP_Joc1_B1 |01-JAN-01| 0

6| 28-DEC-15 |  01-JAN-01   |4  |1  |30000.0    |0.0    |ship   |None   |LP_Joc1_B2 |01-JAN-01| 0

enter image description here

1 个答案:

答案 0 :(得分:1)

//distinct based on a specific property (in this case Name)
List<Objects> listObjects = (from obj in db.Objects                             
                                select obj).GroupBy(n => new {n.Name})
                                           .Select(g => g.FirstOrDefault())
                                           .ToList();