Files
Yi.Framework/CC.Yi/CC.Yi.Common/LinqHelper.cs
橙子 e5063e1a4d v3.0.1
v3.0.1
2021-06-02 20:00:25 +08:00

34 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace CC.Yi.Common
{
public static class LinqHelper
{
//T是列表类型S是排序的属性
public static IQueryable GetPageEntities<T,S>(IQueryable<T> myData, int pageSize, int pageIndex, out int total, Expression<Func<T, bool>> whereLambda=null, Expression<Func<T, S>> orderByLambda=null, bool isAsc=false)
{
total = myData.Where(whereLambda).Count();
if (isAsc)
{
var pageData = myData.Where(whereLambda)
.OrderBy<T,S>(orderByLambda)
.Skip(pageSize * (pageIndex - 1))
.Take(pageSize).AsQueryable();
return pageData;
}
else
{
var pageData = myData.Where(whereLambda)
.OrderByDescending<T, S>(orderByLambda)
.Skip(pageSize * (pageIndex - 1))
.Take(pageSize).AsQueryable();
return pageData;
}
}
}
}