如下:
query = from c in query
group c by c.Id
into cGroup
orderby cGroup.Key
select cGroup.FirstOrDefault();
query = query.OrderBy(c => c.ParentCategoryId).ThenBy(c => c.DisplayOrder);
System.Diagnostics.Trace.WriteLine(query.ToString());
通过 Debug->Windows->OutPut 即可查看输出的sql语句: