mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Update DynamicCoreSelectModel
This commit is contained in:
parent
f6923474ec
commit
0128b8b435
Src/Asp.NetCore2/SqlSugar
@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
@ -25,6 +27,23 @@ namespace SqlSugar
|
||||
return method.Invoke(Value, null);
|
||||
}
|
||||
|
||||
public async Task<object> ToListAsync()
|
||||
{
|
||||
if (Value is null)
|
||||
{
|
||||
throw new InvalidOperationException("Value cannot be null.");
|
||||
}
|
||||
|
||||
var method = Value.GetType().GetMyMethod("ToListAsync", 0);
|
||||
if (method == null)
|
||||
{
|
||||
throw new InvalidOperationException("The Value object does not have a ToListAsync method with no parameters.");
|
||||
}
|
||||
|
||||
var task = (Task)method.Invoke(Value, null);
|
||||
return await GetTask(task).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public object ToPageList(int pageNumber, int pageSize)
|
||||
{
|
||||
if (Value is null)
|
||||
@ -41,6 +60,23 @@ namespace SqlSugar
|
||||
return method.Invoke(Value, new object[] { pageNumber, pageSize });
|
||||
}
|
||||
|
||||
public async Task<object> ToPageListAsync(int pageNumber, int pageSize)
|
||||
{
|
||||
if (Value is null)
|
||||
{
|
||||
throw new InvalidOperationException("Value cannot be null.");
|
||||
}
|
||||
|
||||
var method = Value.GetType().GetMyMethod("ToPageListAsync", 2);
|
||||
if (method == null)
|
||||
{
|
||||
throw new InvalidOperationException("The Value object does not have a ToPageListAsync method with two parameters.");
|
||||
}
|
||||
|
||||
var task = (Task)method.Invoke(Value, new object[] { pageNumber, pageSize });
|
||||
return await GetTask(task).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public object ToPageList(int pageNumber, int pageSize, ref int totalNumber)
|
||||
{
|
||||
if (Value is null)
|
||||
@ -59,5 +95,33 @@ namespace SqlSugar
|
||||
totalNumber = (int)parameters[2];
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<object> ToPageListAsync(int pageNumber, int pageSize, int totalNumber)
|
||||
{
|
||||
if (Value is null)
|
||||
{
|
||||
throw new InvalidOperationException("Value cannot be null.");
|
||||
}
|
||||
|
||||
var method = Value.GetType().GetMyMethod("ToPageListAsync", 3);
|
||||
if (method == null)
|
||||
{
|
||||
throw new InvalidOperationException("The Value object does not have a ToPageListAsync method with three parameters.");
|
||||
}
|
||||
|
||||
var parameters = new object[] { pageNumber, pageSize, totalNumber };
|
||||
var task = (Task)method.Invoke(Value, parameters);
|
||||
var result = await GetTask(task).ConfigureAwait(false);
|
||||
totalNumber = (int)parameters[2];
|
||||
return result;
|
||||
}
|
||||
|
||||
private static async Task<object> GetTask(Task task)
|
||||
{
|
||||
await task.ConfigureAwait(false); // 等待任务完成
|
||||
var resultProperty = task.GetType().GetProperty("Result");
|
||||
var value = resultProperty.GetValue(task);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -332,7 +332,8 @@ namespace SqlSugar
|
||||
public List<T> DataReaderToListNoUsing<T>(IDataReader reader)
|
||||
{
|
||||
var tType = typeof(T);
|
||||
var classProperties = tType.GetProperties().ToList();
|
||||
var classProperties = tType.GetProperties()
|
||||
.Where(p => p.GetIndexParameters().Length == 0).ToList();
|
||||
var reval = new List<T>();
|
||||
if (reader != null && !reader.IsClosed)
|
||||
{
|
||||
@ -357,7 +358,7 @@ namespace SqlSugar
|
||||
using (reader)
|
||||
{
|
||||
var tType = typeof(T);
|
||||
var classProperties = tType.GetProperties().ToList();
|
||||
var classProperties = tType.GetProperties().Where(p => p.GetIndexParameters().Length == 0).ToList();
|
||||
var reval = new List<T>();
|
||||
if (reader != null && !reader.IsClosed)
|
||||
{
|
||||
@ -424,7 +425,7 @@ namespace SqlSugar
|
||||
public async Task<List<T>> DataReaderToListAsyncNoUsing<T>(IDataReader reader)
|
||||
{
|
||||
var tType = typeof(T);
|
||||
var classProperties = tType.GetProperties().ToList();
|
||||
var classProperties = tType.GetProperties().Where(p => p.GetIndexParameters().Length == 0).ToList();
|
||||
var reval = new List<T>();
|
||||
if (reader != null && !reader.IsClosed)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user