百思不得方法-在线求一个Sqlsugar写法 返回

SqlSugar 老数据
2 961

以下是sql语句,在线求,sqlsugar写法。

SELECT Top 10 FailName,Count(FailName) AS Num FROM TestRecords WHERE ((Result) = '0') GROUP BY FailName ORDER BY Count(FailName) DESC;
    public partial class TestRecords
    {
        public TestRecords()
        {
        }

        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        public int ID { get; set; }

        public string FailName { get; set; }

        public string Remark { get; set; }

        public DateTime TestTime { get; set; }
    }


热忱回答2

  • 各位大神,就是Count(FailName) AS Num 不会写,搞New ViewModel也不知道如何是好?

    0 回复
  • db.Queryable<TestRecords>().GroupBy(it => it.FailName) 
                               .Take(10)
                               .Select(it => new { it.FailName, Num = SqlFunc.AggregateCount(it.FailName) })
                               .OrderByDescending(it => it.Num)
                               .ToDataTable();

    自己搞定,感谢各位!

    0 回复