LINQ to SQL does not generate ORDER BY when DISTINCT is used?

前端 未结 2 1906
温柔的废话
温柔的废话 2020-12-06 01:21

The following basic LINQ to SQL statement does not result in the orderby working. As you can see in the T-SQL there is no orderby. Do you know why?

LINQ to

2条回答
  •  我在风中等你
    2020-12-06 01:55

    I got same issue while sorting year from transaction table.

    try this

     var results = (from stats in db.t_harvest_statistics
                           select stats.unit_number).Distinct().OrderBy(x =(Int16)x.unit_number).ToList();
    

    after getting distinct value use orderby method

提交回复
热议问题