2 u011597071 U0115970712016.01.31 02:17 questions

With the pan shape class EF framework (BaseDal), according to the method of conditional query expressions, lambda sort of don't know what to write 1C

MVC in the development of.Net, I use the form class a pan EF framework (BaseDal), I wrote a conditional query on the inside
The method, but the lambda expression of that sort. I don't know what to write

Public static List<T> GetPageListBy<TKey> (int pageIndex, int PageSize, ref int rows, System.Linq.Expressions.Expression<Func<T, bool>> selectWhere, System.Linq.Expressions.Expression<Func<T, TKey>> orderLambda, bool = isAsc true)
{
Using (Mvc_TaoBaoEntities DB = new (Mvc_TaoBaoEntities))
{
RowCount = db.Set<T> (.Where) (selectWhere) (.Count);
If (isAsc)
{
Return (db.Set<T>).Where (selectWhere).OrderBy<T, TKey> (orderLambda).Skip ((pageIndex - 1) * pageSize).Take (pageSize) (.ToList);
}
Else
{
Return (db.Set<T>).Where (selectWhere).OrderByDescending<T, TKey> (orderLambda).Skip ((pageIndex - 1) * pageSize).Take (pageSize) (.ToList);
}
}
}

Call the method
List list = BaseDAL.SelectByPaged (1, 10, 1 = = 1, lambda expression ordering statement ") (.ToList);

The 4 answer

Caozhy
Caozhy   Ds   Rxr 2016.01.31 06:25

List list = BaseDAL.SelectByPaged (1, 10, 1 = = 1, x = x.id) (.ToList); / / such as sorting by ID

Caozhy
Caozhy   Ds   Rxr 2016.01.31 06:26

This is not halo, 1==1

List<Goods> list = BaseDAL<Goods>.SelectByPaged (1, 10, x = X. = x = > what field, X. (.ToList) sort field);
U011597071
U011597071   2016.01.31 02:18
Public static List<T> GetPageListBy<TKey> (int pageIndex, int PageSize, ref int rows, System.Linq.Expressions.Expression<Func<T, bool>> selectWhere, System.Linq.Expressions.Expression<Func<T, TKey>> orderLambda, bool = isAsc true)
{
Using (Mvc_TaoBaoEntities DB = new (Mvc_TaoBaoEntities))
{
RowCount = db.Set<T> (.Where) (selectWhere) (.Count);
If (isAsc)
{
Return (db.Set<T>).Where (selectWhere).OrderBy<T, TKey> (orderLambda).Skip ((pageIndex - 1) * pageSize).Take (pageSize) (.ToList);
}
Else
{
Return (db.Set<T>).Where (selectWhere).OrderByDescending<T, TKey> (orderLambda).Skip ((pageIndex - 1) * pageSize).Take (pageSize) (.ToList);
}
}
}
U011597071
U011597071   2016.01.31 02:19

The online answer, God came to help ah

Csdn user default icon
Upload...
Upload photo
Insert a picture