ServiceStack MAX和MIN查询

时间:2013-09-24 15:30:58

标签: ormlite-servicestack

相对较新的ServiceStack,我不知道该怎么做......

我有一个名为NextHint的对象,它为用户提供了一个提示。

    [AutoIncrement]
    public int Id { get; set; }
    public string Body { get; set; }
    public string Title { get; set; }
    public int VoteCount { get; set; }
    public int TimesShown { get; set; }

我正在尝试找到票数最高的提示(MAX(VoteCount))并且最少见(MIN(TimesShown))。逻辑的基本原理不是重点,而是SQL机制。

我的方法目前看起来像......

public object Get(NextHint request)
    {
        Hint hint;
        using (var db = DbConnectionFactory.OpenDbConnection())
        {
            //Don't know what to do here!!!
            db.Single<Hint>("MIN(TimesShown) and MAX(VoteCount) group by Id");

            //Update the count of TimesShown 
            hint.TimesShown++;
            db.Update(hint);
        }
        return new NextHintResponse { Title = hint.Title, Body = hint.Body };
    }

有人能指出我正确的方向吗? BTW - 我正在使用MySql,但希望解决方案保持通用。

0 个答案:

没有答案