Browse Source

Optimized code

pull/40/head
sunkaixuan 1 year ago
parent
commit
2febf7c58d
  1. 44
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs

44
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs

@ -98,17 +98,17 @@ namespace SqlSugar
public virtual List<TResult> ToList<TResult>(Expression<Func<T, TResult>> expression) public virtual List<TResult> ToList<TResult>(Expression<Func<T, TResult>> expression)
{ {
if (this.QueryBuilder.Includes != null && this.QueryBuilder.Includes.Count > 0) //if (this.QueryBuilder.Includes != null && this.QueryBuilder.Includes.Count > 0)
{ //{
return NavSelectHelper.GetList(expression, this); // return NavSelectHelper.GetList(expression, this);
// var list = this.ToList().Select(expression.Compile()).ToList(); // // var list = this.ToList().Select(expression.Compile()).ToList();
// return list; // // return list;
} //}
else //else
{ //{
var list = this.Select(expression).ToList(); var list = this.Select(expression).ToList();
return list; return list;
} //}
} }
public virtual int Count() public virtual int Count()
@ -668,21 +668,21 @@ namespace SqlSugar
} }
public virtual List<TResult> ToPageList<TResult>(int pageIndex, int pageSize, ref int totalNumber, Expression<Func<T, TResult>> expression) public virtual List<TResult> ToPageList<TResult>(int pageIndex, int pageSize, ref int totalNumber, Expression<Func<T, TResult>> expression)
{ {
if (this.QueryBuilder.Includes != null && this.QueryBuilder.Includes.Count > 0) //if (this.QueryBuilder.Includes != null && this.QueryBuilder.Includes.Count > 0)
{ //{
if (pageIndex == 0) // if (pageIndex == 0)
pageIndex = 1; // pageIndex = 1;
var list = this.Clone().Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(expression); // var list = this.Clone().Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(expression);
var countQueryable = this.Clone(); // var countQueryable = this.Clone();
countQueryable.QueryBuilder.Includes = null; // countQueryable.QueryBuilder.Includes = null;
totalNumber = countQueryable.Count(); // totalNumber = countQueryable.Count();
return list; // return list;
} //}
else //else
{ //{
var list = this.Select(expression).ToPageList(pageIndex, pageSize, ref totalNumber).ToList(); var list = this.Select(expression).ToPageList(pageIndex, pageSize, ref totalNumber).ToList();
return list; return list;
} //}
} }
public virtual List<T> ToPageList(int pageIndex, int pageSize, ref int totalNumber) public virtual List<T> ToPageList(int pageIndex, int pageSize, ref int totalNumber)
{ {

Loading…
Cancel
Save