using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Dynamic;
namespace LinqTest
{
class Program
{
static void Main(string[] args)
{
List<Sample> sampleData = new List<Sample>()
{
new Sample{ ID=1, Name="V", Designation="Executive", JoiningDate=DateTime.Now.Date, Salary=45000M },
new Sample{ ID=2, Name="F", Designation="Executive", JoiningDate=DateTime.Now.Date, Salary=400M },
new Sample{ ID=3, Name="A", Designation="Boss", JoiningDate=DateTime.Now.Date, Salary=5000M },
new Sample{ ID=1, Name="D", Designation="Executive", JoiningDate=DateTime.Now.Date, Salary=2500M },
new Sample{ ID=1, Name="V", Designation="Executive", JoiningDate=DateTime.Now.Date, Salary=45000M }
};
IQueryable<Sample> sas = sampleData.AsQueryable<Sample>();
sas.OrderBy("Name");
}
}
}
正如您在上面所看到的,我正在尝试使用System.Linq.Dynamic
库的扩展方法对其中一个列进行简单排序。但它没有被分类。当我将鼠标悬停在sas
上时,我会看到原始订单中的商品。有人可以告诉我为什么吗?
答案 0 :(得分:7)
原始sas
变量仍然无序。您需要保存OrderBy
的结果:
var myOrderedSas = sas.OrderBy("Name");