From f2ab18a1000c016df139b948b84ff3ac424ba0f0 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 16 Jul 2023 15:50:29 +0800 Subject: [PATCH] Add Queryable.ToDataTableByEntityPage --- .../QueryableProvider/QueryableExecuteSql.cs | 11 ++++++++++- .../QueryableProvider/QueryableExecuteSqlAsync.cs | 13 +++++++++++-- Src/Asp.Net/SqlSugar/Interface/IQueryable.cs | 4 ++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs index 1a9aa5a54..23a848d00 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs @@ -353,7 +353,11 @@ namespace SqlSugar var list = this.ToList(); return TreeAndFilterIds(childListExpression, parentIdExpression, rootValue, childIds, ref list) ?? new List(); } - + public virtual DataTable ToDataTableByEntity() + { + var list = this.ToList(); + return this.Context.Utilities.ListToDataTable(list); + } public virtual DataTable ToDataTable() { QueryBuilder.ResultType = typeof(SugarCacheDataTable); @@ -392,6 +396,11 @@ namespace SqlSugar } return ToDataTable(); } + public DataTable ToDataTableByEntityPage(int pageNumber, int pageSize, ref int totalNumber) + { + var list=this.ToPageList(pageNumber, pageSize,ref totalNumber); + return this.Context.Utilities.ListToDataTable(list); + } public virtual DataTable ToDataTablePage(int pageIndex, int pageSize, ref int totalNumber) { _RestoreMapping = false; diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSqlAsync.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSqlAsync.cs index 4e48d6d06..7efc75dd2 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSqlAsync.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSqlAsync.cs @@ -10,7 +10,7 @@ using System.Reflection; using System.Dynamic; using System.Threading.Tasks; using System.Threading; - + namespace SqlSugar { @@ -350,7 +350,11 @@ namespace SqlSugar this.Context.MappingTables = oldMapping; return await this.Clone().ToJsonPageAsync(pageIndex, pageSize); } - + public async virtual Task ToDataTableByEntityAsync() + { + var list =await this.ToListAsync(); + return this.Context.Utilities.ListToDataTable(list); + } public async Task ToDataTableAsync() { QueryBuilder.ResultType = typeof(SugarCacheDataTable); @@ -381,6 +385,11 @@ namespace SqlSugar this.Context.MappingTables = oldMapping; return await this.Clone().ToDataTablePageAsync(pageIndex, pageSize); } + public async Task ToDataTableByEntityPageAsync(int pageNumber, int pageSize, RefAsync totalNumber) + { + var list =await this.ToPageListAsync(pageNumber, pageSize, totalNumber); + return this.Context.Utilities.ListToDataTable(list); + } public async Task> ToOffsetPageAsync(int pageIndex, int pageSize, RefAsync totalNumber) { if (this.Context.CurrentConnectionConfig.DbType != DbType.SqlServer) diff --git a/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs b/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs index f0b86d691..cb38bb419 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs @@ -234,12 +234,16 @@ namespace SqlSugar List ToTree(Expression>> childListExpression, Expression> parentIdExpression, object rootValue, object[] childIds); Task> ToTreeAsync(Expression>> childListExpression, Expression> parentIdExpression, object rootValue, object[] childIds); DataTable ToDataTable(); + DataTable ToDataTableByEntity(); Task ToDataTableAsync(); + Task ToDataTableByEntityAsync(); DataTable ToDataTablePage(int pageNumber, int pageSize); Task ToDataTablePageAsync(int pageNumber, int pageSize); DataTable ToDataTablePage(int pageNumber, int pageSize, ref int totalNumber); + DataTable ToDataTableByEntityPage(int pageNumber, int pageSize, ref int totalNumber); DataTable ToDataTablePage(int pageNumber, int pageSize, ref int totalNumber,ref int totalPage); Task ToDataTablePageAsync(int pageNumber, int pageSize, RefAsync totalNumber); + Task ToDataTableByEntityPageAsync(int pageNumber, int pageSize, RefAsync totalNumber); List ToOffsetPage(int pageNumber, int pageSize); List ToOffsetPage(int pageNumber, int pageSize,ref int totalNumber);