.net Linq

今天取数据,遇到麻烦事儿,不想懂后台程序,只能用Linq,但是只听过没用过,经过简单的入门,终于实现了我想要的效果。

获取集合升序中除了最后一条其他的数据,因为我需要最后一条排序是最新的数据,其他的是历史数据,在这里我需要历史数据!

IList<PsychConPlanInfo> pslst = IMPCP.GetList(psinfo, 5, 1).OrderBy(i => i.CreateTime).ToList();
int count = pslst.Count();
var query = (from o in pslst orderby o.CreateTime ascending select o).Take(count-1).ToList();

用到Linq Take()。取数据前几条,还有一个是Skip()去数据后几条。

在网上搜索很多相关用法,只说在(from o in pslst orderby o.CreateTime ascending select o)查询后面加上Take().结果没有值。又琢磨了半天才发现需要转为集合ToList()才可以!

随笔!

posted @ 2012-02-16 17:00  ω♪zone咕咯  阅读(262)  评论(0编辑  收藏  举报