日期:2014-05-20  浏览次数:20969 次

linq如何根据计算值进行排序
如题:
查询代码如下:
var result = from a in db.CustomerProjectTable
  join b in db.AccountTable on a.AccountID equals b.AccountID
  join c in db.AccountTable on a.CheckerID equals c.AccountID
  join d in db.StatusTable on a.Status equals d.ChildID
  where new int[]{(int)CustomerProjectStatus.Building,(int)CustomerProjectStatus.BuildCompleted,(int)CustomerProjectStatus.ConsCompleted}.Contains(a.Status)
  select new
  {
  a.CPID,
  a.ProjectCode,
  AccountName = b.ScreenName,
  CheckerName = c.ScreenName,
  IsRemind=this.IsRemind(a.CPID),
  RemindDay=this.GetLeftRemindDays(a.CPID),
  CreateTime = String.Format(@"{0:yy-MM-dd}",a.CreateTime),
  CheckTime = !a.CheckTime.HasValue ? "-" : String.Format(@"{0:yy-MM-dd}", a.CheckTime),
  a.ProjectName,
  StatusName = d.EN_Name,
  PlanTime=String.Format(@"{0:yy-MM-dd}",GetEndDate(a.CPID)),
  RunTime=String.Format(@"{0:yy-MM-dd}",a.RunTime),
  RealTime = String.Format(@"{0:yy-MM-dd}", a.RealTime),
  URL = UrlMgr.GetUrlForCustomerProjectEdit(a.CPID),
  WakeAudit = this.GetWakeAudit(a.CPID)
  };


结果集中的RemindDay的值是通过方法计算得出来的。。不是数据库中应有的字段,我现在要根据RemindDay进行排序,哪位大虾知道的帮帮忙,小弟感激不尽。
注: result=result.OrderBy(a=>a.RemindDay);和在查询中排序都不行。。

------解决方案--------------------
在最后使用之前(返回给前台)再排序
------解决方案--------------------
ToList()
再排序

------解决方案--------------------
大致应该写为了类似:
C# code
  where CustomerProjectStatus.Building==a.Status ||
    CustomerProjectStatus==a.Status || BuildCompleted==a.Status ||
    CustomerProjectStatus.ConsCompleted==a.Status
  let r=this.GetLeftRemindDays(a.CPID)
  order by r
  select .......

------解决方案--------------------
探讨

大致应该写为了类似:C# code
where CustomerProjectStatus.Building==a.Status ||
CustomerProjectStatus==a.Status || BuildCompleted==a.Status ||
CustomerProjectStatus.ConsCompleted==a.Status
let r=thi……