日期:2014-05-17 浏览次数:20873 次
public List<Abc> Get(string Order,string Sort)
{
//如果这样写,就默认是按ModuleTypeId进行ASC排序
List<Abc> listAbc = Abc.GetAll().OrderBy(k => k.AbcId).ToList();
return listAbc;
//用什么办法可以根据传进来的Order参数确定排序的列,根据Sort确定排序类型?
}
public List<Abc> Get(string Order, string Sort)
{
//如果这样写,就默认是按ModuleTypeId进行ASC排序
List<Abc> listAbc = Abc.GetAll().OrderBy(k => string.Compare(Sort, "xxxxx") == 0 ? k.AbcId : k.ModuleTypeId).ToList();
return listAbc;
}
var param = Expression.Parameter(typeof(ABC), "k");
var body = Expression.MakeMemberAccess(param, typeof(ABC).GetProperty(Sort));
var lambdaexpr = Expression.Lambda(param, body);
return List<Abc> listAbc = Abc.GetAll().OrderBy(lambdaexpr.Compile() as Func<Abc, ICompareable>).ToList();
class Pet
{
public string Name{get;set;}
public int Age{get;set;}