I want to query distinct state names in a datatable called ZipTable, and use alpha-beta order to list the state name, but it does not work. Did I miss something?
public List<String> GetAllStates()
{
ZipTableDataContext dc = new ZipTableDataContext(_connString);
List<String> query = (from z in dc.ZipTables
orderby z.State
select z.State).Distinct().ToList();
return query;
}
The call to
Distinct()will undo your ordering, since it does not preserve the input sequence order. You need to perform yourOrderByafter theDistinct()call: