Exemple #1
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            List <People> list = new List <People>();

            list.Add(new People {
                Id = 1, Name = "a1"
            });
            list.Add(new People {
                Id = 2, Name = "a2"
            });
            list.Add(new People {
                Id = 3, Name = "a3"
            });

            // 定义排序规则
            Action <IOrderable <People> > orderBy = o => o.Asc(j => j.Id)
                                                    .ThenDesc(j => j.Name);
            // 数据仓储
            Repository <People> repository = new Repository <People>(list.AsQueryable());

            // 获取结果
            List <People> result = repository.GetModel(orderBy).ToList();

            // 输出
            result.ToList().ForEach(i => Console.WriteLine(i.Id));

            //简单的调用
            Action <IOrderable <People> > orderByDesc = o => o.Desc(j => j.Id);
            var linq = new Orderable <People>(list.AsQueryable());

            orderByDesc(linq);
            linq.Queryable.ToList().ForEach(i => Console.WriteLine(i.Id));
        }
Exemple #2
0
        public IQueryable <TEntity> GetModel(Action <IOrderable <TEntity> > orderBy)
        {
            var linq = new Orderable <TEntity>(GetModel());

            orderBy(linq);
            return(linq.Queryable);
        }