请教一个关于Linq的OrderByDescending的问题

名字都被起了 2015-11-30 04:52:59
业务要求是用linq多表查询,并且按照某个表中的某一个字段进行排序

var listItem = from l in db.ListItem
from g in db.Goods
from p in db.gPic
where l.enable == true && l.gid == g.gId && p.gid == g.gId && l.status == 1
orderby l.existingTimes descending
select new
{
existingTime = l.existingTimes,
status = l.status,
desc = g.descString,
priceBase = g.priceBase,
gpic = p.gid,
showPicNum = g.showPicNum,
tag = g.tag,
gname = g.gName,
priceType = g.priceType,
property = g.property,
priceUnit = g.priceUnit,
regularBuyMax = g.regularBuyMax,
price = g.price,
buyUnit = g.buyUnit,
gid = g.gId,
buyable = g.buyAble,
brand = g.brand,
wishSetable = g.wishSetable,
typeId = g.typeId,
limitTime = l.limitTime,
isLimit = l.isLimit,
listIcons = l.listIcons,
period = l.period,
totalPeriod = l.totalPeriod,
//isJoined = l.isJoined
};

然后这个结果是重复了三遍=.=
于是用了Distinct()这个方法,然后排序就变成默认排序了
于是想用OrderByDescending这个方法,请教下这个方法怎么用呢~
谢谢各位~~~~~~~~~~~~~~
...全文
313 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
exception92 2015-11-30
  • 打赏
  • 举报
回复
引用 2 楼 bzyhd 的回复:
那就结贴吧,结贴可得一般可用分。
一般-》一半
现在ing 2015-11-30
  • 打赏
  • 举报
回复
那就结贴吧,结贴可得一般可用分。
名字都被起了 2015-11-30
  • 打赏
  • 举报
回复
已解决,原来是后面的代码没仔细检查, 直接listItem.OrderByDescending(o=>o.existingTimes)这样使用即可~

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧