OrderByDesc col1除以col2

时间:2012-09-18 08:56:11

标签: c# linq entity-framework lambda

我需要sort基于col1除以col2的结果...所以我想做的是这样的:

var x = uploadsQuerySelectionBuilder.Where(e => e.uploadNumberOfVotes 
> 0)**.OrderByDescending(e=>(e.uploadScore/e.uploadNumberOfVotes))
** : uploadsQuerySelectionBuilder;

至于现在..它似乎根本没有订购结果,但它只是随机.. 这甚至是可能的,我怎么能让这个工作?

编辑:

var x = tSearch.SortByDate != false ? uploadsQuerySelectionBuilder.Where(e => e.uploadNumberOfVotes > 0).OrderByDescending(e => (e.uploadScore / e.uploadNumberOfVotes)) : uploadsQuerySelectionBuilder;

是非常有效且“可编译”的代码:) ..另一个不是用VS编写的,所以我的不好......

1 个答案:

答案 0 :(得分:0)

类似的东西:

var x = uploadsQuerySelectionBuilder
           .Where(e => e.uploadNumberOfVotes > 0)
           .Select(e => new { Val = e, ScoreishThing = e.uploadScore/e.uploadNumberOfVotes })
           .OrderByDescending(e=> e.ScoreishThing)
           .Select(e=>e.Val);