当前位置:编程学习 > C#/ASP.NET >>

entities 可以实现sql case ... when ...then 排序吗?

select HJ_AllNews.MediaName,HJ_AllNews.ClipTime,convert(varchar(10),HJ_AllNews.ClipTime,120) as ClipTime2, _Lexus_Clippings.ClientPressReleaseID,_Lexus_Clippings.ClientMediaTypeID, _Lexus_Clippings.ID as ClientObjID, _Lexus_Clippings.ClientCatalogID as ClientCatalogID,HJ_AllNews.* from HJ_AllNews join _Lexus_Clippings on HJ_AllNews.ID=_Lexus_Clippings.ClippingsID join ClientDailyReport on _Lexus_Clippings.ID=ClientDailyReport.ClientClipID where ClientDailyReport.ClientDailyCatalogID=@DailyCatalogID order by ClipTime2 DESC,HJ_AllNews.MediaTypeID, case HJ_AllNews.MediaName when '腾讯网' then 1 when '搜狐网' then 2 when '网易' then 3 when '新浪网' then 4 else 5 end,HJ_AllNews.MediaName

请问:case HJ_AllNews.MediaName when '腾讯网' then 1 when '搜狐网' then 2 when '网易' then 3 when '新浪网' then 4 else 5 end

这样的排序用entities 如何实现呢?高手指教 --------------------编程问答-------------------- 最简单的方法套个子查询

select * from (你的sql语句) order by 排序字段 --------------------编程问答-------------------- 最简单的方法套个子查询

select * from (你的sql语句) A order by 排序字段 --------------------编程问答-------------------- 我是想用 linq 4.0 entity 实现 --------------------编程问答--------------------
引用 3 楼 myplay2010 的回复:
我是想用 linq 4.0 entity 实现


有什么区别么?你实体直接用子查询结果就是了 --------------------编程问答-------------------- 给个例子 子程序怎样写在List<T>查询中 --------------------编程问答-------------------- 我自己想出来了,哈哈

   string[]  medias = new string [] { "新华网", "中国新闻网", "人民网", "新浪网", "搜狐网", "网易", "腾讯网", "中国网", "凤凰网", "MSN中国", "中国经济网", "和讯网", "慧聪网" };

        List<HJ_AllNews> allNews = (new ClientBaseCatalogData(_clientID, curCategory.CatalogID)).GetNewsByTime2(this.startTime, this.endTime, this.timeType, this.sort, "652,653,654,655,656,657").OrderBy(p=>int.Parse(p.ClientMediaTypeID)).ThenBy(p => DateTime.Parse(p.ClipTime).Date).ThenBy(p=>Array.IndexOf(medias,p.MediaName.Trim())!=-1?Array.IndexOf(medias,p.MediaName.Trim()):15).ToList();
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,