以下行不起作用,因为distinct()不提供有序输出。
var context= new BatchEntities();//Entity model
var practices = (from p in context.EMSCAN_BATCH orderby p.PRACTICE select p.PRACTICE).Distinct();
试过这个:
var practices = (from p in context.EMSCAN_BATCH
select p.PRACTICE).Distinct().OrderBy(x=>x.PRACTICE);
这给出了字符串不包含'PRACTICE'定义的错误.... 还试过这个:
var practices =(from p in context.EMSCAN_BATCH
select new
{
p.PRACTICE
}).Distinct().OrderBy(x=>x.PRACTICE);
这会产生错误的输出。
答案 0 :(得分:1)
只需从PRACTICE
OrderBy
即可
var practices = (from p in context.EMSCAN_BATCH
select p.PRACTICE).Distinct().OrderBy(x => x);
答案 1 :(得分:0)
或者你可以这样做:
var practices = context.EMSCAN_BATCH.SELECT(m => m.PRACTICE).Distinct().OrderBy(m => m.PRACTICE);