按顺序使用

时间:2014-06-18 00:01:55

标签: linq

问题在于,我继承了用asp.net编写的数据库驱动应用程序......

目前它有一行

var ovs = (from i in data.ADS_TESTs orderby i.SampleNumber descending select i).Take(numToFetch);

我对此非常陌生,是一个php和sql背景..

我如何在那里写一个圆函数,例如在sql中我会写

ORDER BY ROUND(SampleNumber, 0) DESC, SampleNumber

2 个答案:

答案 0 :(得分:0)

大多数查询提供程序通常支持使用常见的静态方法。假设LINQ to SQL,它支持使用Math.Round()

var ovs =
    (from i in data.ADS_TESTs
            // the overload of Round() supported needs the rounding mode
    orderby Math.Round(i.SampleNumber, MidpointRounding.AwayFromZero) descending,
            i.SampleNumber
    select i).Take(numToFetch);

答案 1 :(得分:0)

你可以在orderby子句之后操作i.SampleNumber。 是的,因为杰夫告诉Math.Round()可以使用。

相关问题