2017-02-25 144 views
1

我想按照DESC顺序排序数据。这是我的代码:如何使用Dapper扩展中的DESC顺序,按照Order by子句对数据进行排序?

var predicate = Predicates.Sort<myPoco>(x => x.name, false); 
var result = GetList<myPoco>(predicate).ToList(); 

protected IEnumerable<T> GetList<T>(object predicate, IList<ISort> sort = null, IDbTransaction transaction = null, int? commandTimeout = null, bool buffered = false) where T : class 
{ 
    var result = connection.GetList<T>(predicate, sort, transaction, commandTimeout, buffered); 
    return 
} 

使用Dapper扩展,我无法对数据进行排序。上面的代码引发以下错误:

PropertyName was not found for...

我使用映射扩展精致小巧的ClassMappermyPoco财产。

回答

1

您可以使用Dapper Extension的ISort对数据进行排序。

List<ISort> sortList = new List<ISort>(); 
sortList.Add(Predicates.Sort<myPoco>(x => x.Name, false)); 

var result = GetList<myPoco>(null, sortList).ToList(); 
return result; 

    protected IEnumerable<T> GetList<T>(object predicate, IList<ISort> sort = null, IDbTransaction transaction = null, int? commandTimeout = null, bool buffered = false) where T : class 
    { 
        var result = connection.GetList<T>(predicate, sort, transaction, commandTimeout, buffered); 
        return result; 
    } 
相关问题