Entity Framework select distinct name

前端 未结 8 1915
小蘑菇
小蘑菇 2020-12-12 14:18

How can I do this SQL query with Entity Framework?

SELECT DISTINCT NAME FROM TestAddresses
8条回答
  •  天命终不由人
    2020-12-12 14:50

    In order to avoid ORDER BY items must appear in the select list if SELECT DISTINCT error, the best should be

    var results = (
        from ta in DBContext.TestAddresses
        select ta.Name
    )
    .Distinct()
    .OrderBy( x => 1);
    

提交回复
热议问题