mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-24 07:22:57 +08:00
-
This commit is contained in:
parent
b063d18134
commit
72a8917380
@ -49,6 +49,9 @@ namespace OrmTest
|
|||||||
UValidate.Check(8, task8.Result[0].id, "ado");
|
UValidate.Check(8, task8.Result[0].id, "ado");
|
||||||
|
|
||||||
var task9=Db.Ado.SqlQuery<Order, OrderItem>("select * from [order];select * from OrderDetail");
|
var task9=Db.Ado.SqlQuery<Order, OrderItem>("select * from [order];select * from OrderDetail");
|
||||||
|
|
||||||
|
var task10 = Db.Ado.SqlQueryAsync<Order, OrderItem>("select * from [order];select * from OrderDetail");
|
||||||
|
task10.Wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -834,49 +834,49 @@ namespace SqlSugar
|
|||||||
List<T> result = new List<T>();
|
List<T> result = new List<T>();
|
||||||
if (DbReader.HasRows)
|
if (DbReader.HasRows)
|
||||||
{
|
{
|
||||||
result = this.DbBind.DataReaderToListNoUsing<T>(typeof(T), dataReader);
|
result = GetData<T>(typeof(T), dataReader);
|
||||||
}
|
}
|
||||||
List<T2> result2 = null;
|
List<T2> result2 = null;
|
||||||
if (DbReader.HasRows)
|
if (DbReader.HasRows)
|
||||||
{
|
{
|
||||||
this.Context.InitMappingInfo<T2>();
|
this.Context.InitMappingInfo<T2>();
|
||||||
NextResult(dataReader);
|
NextResult(dataReader);
|
||||||
result2 = this.DbBind.DataReaderToListNoUsing<T2>(typeof(T2), dataReader);
|
result2 = GetData<T2>(typeof(T2), dataReader);
|
||||||
}
|
}
|
||||||
List<T3> result3 = null;
|
List<T3> result3 = null;
|
||||||
if (DbReader.HasRows)
|
if (DbReader.HasRows)
|
||||||
{
|
{
|
||||||
this.Context.InitMappingInfo<T3>();
|
this.Context.InitMappingInfo<T3>();
|
||||||
NextResult(dataReader);
|
NextResult(dataReader);
|
||||||
result3 = this.DbBind.DataReaderToListNoUsing<T3>(typeof(T3), dataReader);
|
result3 = GetData<T3>(typeof(T3), dataReader);
|
||||||
}
|
}
|
||||||
List<T4> result4 = null;
|
List<T4> result4 = null;
|
||||||
if (DbReader.HasRows)
|
if (DbReader.HasRows)
|
||||||
{
|
{
|
||||||
this.Context.InitMappingInfo<T4>();
|
this.Context.InitMappingInfo<T4>();
|
||||||
NextResult(dataReader);
|
NextResult(dataReader);
|
||||||
result4 = this.DbBind.DataReaderToListNoUsing<T4>(typeof(T4), dataReader);
|
result4 = GetData<T4>(typeof(T4), dataReader);
|
||||||
}
|
}
|
||||||
List<T5> result5 = null;
|
List<T5> result5 = null;
|
||||||
if (DbReader.HasRows)
|
if (DbReader.HasRows)
|
||||||
{
|
{
|
||||||
this.Context.InitMappingInfo<T5>();
|
this.Context.InitMappingInfo<T5>();
|
||||||
NextResult(dataReader);
|
NextResult(dataReader);
|
||||||
result5 = this.DbBind.DataReaderToListNoUsing<T5>(typeof(T5), dataReader);
|
result5 = GetData<T5>(typeof(T5), dataReader);
|
||||||
}
|
}
|
||||||
List<T6> result6 = null;
|
List<T6> result6 = null;
|
||||||
if (DbReader.HasRows)
|
if (DbReader.HasRows)
|
||||||
{
|
{
|
||||||
this.Context.InitMappingInfo<T6>();
|
this.Context.InitMappingInfo<T6>();
|
||||||
NextResult(dataReader);
|
NextResult(dataReader);
|
||||||
result6 = this.DbBind.DataReaderToListNoUsing<T6>(typeof(T6), dataReader);
|
result6 = GetData<T6>(typeof(T6), dataReader);
|
||||||
}
|
}
|
||||||
List<T7> result7 = null;
|
List<T7> result7 = null;
|
||||||
if (DbReader.HasRows)
|
if (DbReader.HasRows)
|
||||||
{
|
{
|
||||||
this.Context.InitMappingInfo<T7>();
|
this.Context.InitMappingInfo<T7>();
|
||||||
NextResult(dataReader);
|
NextResult(dataReader);
|
||||||
result7 = this.DbBind.DataReaderToListNoUsing<T7>(typeof(T7), dataReader);
|
result7 = GetData<T7>(typeof(T7), dataReader);
|
||||||
}
|
}
|
||||||
builder.SqlQueryBuilder.Clear();
|
builder.SqlQueryBuilder.Clear();
|
||||||
if (this.Context.Ado.DataReaderParameters != null)
|
if (this.Context.Ado.DataReaderParameters != null)
|
||||||
@ -955,49 +955,49 @@ namespace SqlSugar
|
|||||||
List<T> result = new List<T>();
|
List<T> result = new List<T>();
|
||||||
if (DbReader.HasRows)
|
if (DbReader.HasRows)
|
||||||
{
|
{
|
||||||
result =await this.DbBind.DataReaderToListNoUsingAsync<T>(typeof(T), dataReader);
|
result =await GetDataAsync<T>(typeof(T), dataReader);
|
||||||
}
|
}
|
||||||
List<T2> result2 = null;
|
List<T2> result2 = null;
|
||||||
if (DbReader.HasRows)
|
if (DbReader.HasRows)
|
||||||
{
|
{
|
||||||
this.Context.InitMappingInfo<T2>();
|
this.Context.InitMappingInfo<T2>();
|
||||||
NextResult(dataReader);
|
NextResult(dataReader);
|
||||||
result2 = await this.DbBind.DataReaderToListNoUsingAsync<T2>(typeof(T2), dataReader);
|
result2 = await GetDataAsync<T2>(typeof(T2), dataReader);
|
||||||
}
|
}
|
||||||
List<T3> result3 = null;
|
List<T3> result3 = null;
|
||||||
if (DbReader.HasRows)
|
if (DbReader.HasRows)
|
||||||
{
|
{
|
||||||
this.Context.InitMappingInfo<T3>();
|
this.Context.InitMappingInfo<T3>();
|
||||||
NextResult(dataReader);
|
NextResult(dataReader);
|
||||||
result3 = await this.DbBind.DataReaderToListNoUsingAsync<T3>(typeof(T3), dataReader);
|
result3 = await GetDataAsync<T3>(typeof(T3), dataReader);
|
||||||
}
|
}
|
||||||
List<T4> result4 = null;
|
List<T4> result4 = null;
|
||||||
if (DbReader.HasRows)
|
if (DbReader.HasRows)
|
||||||
{
|
{
|
||||||
this.Context.InitMappingInfo<T4>();
|
this.Context.InitMappingInfo<T4>();
|
||||||
NextResult(dataReader);
|
NextResult(dataReader);
|
||||||
result4 = await this.DbBind.DataReaderToListNoUsingAsync<T4>(typeof(T4), dataReader);
|
result4 = await GetDataAsync<T4>(typeof(T4), dataReader);
|
||||||
}
|
}
|
||||||
List<T5> result5 = null;
|
List<T5> result5 = null;
|
||||||
if (DbReader.HasRows)
|
if (DbReader.HasRows)
|
||||||
{
|
{
|
||||||
this.Context.InitMappingInfo<T5>();
|
this.Context.InitMappingInfo<T5>();
|
||||||
NextResult(dataReader);
|
NextResult(dataReader);
|
||||||
result5 = await this.DbBind.DataReaderToListNoUsingAsync<T5>(typeof(T5), dataReader);
|
result5 = await GetDataAsync<T5>(typeof(T5), dataReader);
|
||||||
}
|
}
|
||||||
List<T6> result6 = null;
|
List<T6> result6 = null;
|
||||||
if (DbReader.HasRows)
|
if (DbReader.HasRows)
|
||||||
{
|
{
|
||||||
this.Context.InitMappingInfo<T6>();
|
this.Context.InitMappingInfo<T6>();
|
||||||
NextResult(dataReader);
|
NextResult(dataReader);
|
||||||
result6 = await this.DbBind.DataReaderToListNoUsingAsync<T6>(typeof(T6), dataReader);
|
result6 = await GetDataAsync<T6>(typeof(T6), dataReader);
|
||||||
}
|
}
|
||||||
List<T7> result7 = null;
|
List<T7> result7 = null;
|
||||||
if (DbReader.HasRows)
|
if (DbReader.HasRows)
|
||||||
{
|
{
|
||||||
this.Context.InitMappingInfo<T7>();
|
this.Context.InitMappingInfo<T7>();
|
||||||
NextResult(dataReader);
|
NextResult(dataReader);
|
||||||
result7 = await this.DbBind.DataReaderToListNoUsingAsync<T7>(typeof(T7), dataReader);
|
result7 = await GetDataAsync<T7>(typeof(T7), dataReader);
|
||||||
}
|
}
|
||||||
builder.SqlQueryBuilder.Clear();
|
builder.SqlQueryBuilder.Clear();
|
||||||
if (this.Context.Ado.DataReaderParameters != null)
|
if (this.Context.Ado.DataReaderParameters != null)
|
||||||
@ -1417,6 +1417,49 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private List<TResult> GetData<TResult>(Type entityType, IDataReader dataReader)
|
||||||
|
{
|
||||||
|
List<TResult> result;
|
||||||
|
if (entityType == UtilConstants.DynamicType)
|
||||||
|
{
|
||||||
|
result = this.Context.Utilities.DataReaderToExpandoObjectListNoUsing(dataReader) as List<TResult>;
|
||||||
|
}
|
||||||
|
else if (entityType == UtilConstants.ObjType)
|
||||||
|
{
|
||||||
|
result = this.Context.Utilities.DataReaderToExpandoObjectListNoUsing(dataReader).Select(it => ((TResult)(object)it)).ToList();
|
||||||
|
}
|
||||||
|
else if (entityType.IsAnonymousType())
|
||||||
|
{
|
||||||
|
result = this.Context.Utilities.DataReaderToListNoUsing<TResult>(dataReader);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = this.Context.Ado.DbBind.DataReaderToListNoUsing<TResult>(entityType, dataReader);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
private async Task<List<TResult>> GetDataAsync<TResult>(Type entityType, IDataReader dataReader)
|
||||||
|
{
|
||||||
|
List<TResult> result;
|
||||||
|
if (entityType == UtilConstants.DynamicType)
|
||||||
|
{
|
||||||
|
result =await this.Context.Utilities.DataReaderToExpandoObjectListAsyncNoUsing(dataReader) as List<TResult>;
|
||||||
|
}
|
||||||
|
else if (entityType == UtilConstants.ObjType)
|
||||||
|
{
|
||||||
|
var list = await this.Context.Utilities.DataReaderToExpandoObjectListAsyncNoUsing(dataReader);
|
||||||
|
result = list.Select(it => ((TResult)(object)it)).ToList();
|
||||||
|
}
|
||||||
|
else if (entityType.IsAnonymousType())
|
||||||
|
{
|
||||||
|
result =await this.Context.Utilities.DataReaderToListAsyncNoUsing<TResult>(dataReader);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result =await this.Context.Ado.DbBind.DataReaderToListNoUsingAsync<TResult>(entityType, dataReader);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Obsolete
|
#region Obsolete
|
||||||
|
@ -82,6 +82,44 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///DataReader to Dynamic List
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="reader"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<ExpandoObject> DataReaderToExpandoObjectListNoUsing(IDataReader reader)
|
||||||
|
{
|
||||||
|
List<ExpandoObject> result = new List<ExpandoObject>();
|
||||||
|
if (reader != null && !reader.IsClosed)
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
result.Add(DataReaderToExpandoObject(reader));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///DataReader to Dynamic List
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="reader"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<List<ExpandoObject>> DataReaderToExpandoObjectListAsyncNoUsing(IDataReader reader)
|
||||||
|
{
|
||||||
|
List<ExpandoObject> result = new List<ExpandoObject>();
|
||||||
|
if (reader != null && !reader.IsClosed)
|
||||||
|
{
|
||||||
|
while (await ((DbDataReader)reader).ReadAsync())
|
||||||
|
{
|
||||||
|
result.Add(DataReaderToExpandoObject(reader));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///DataReader to DataReaderToDictionary
|
///DataReader to DataReaderToDictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -165,6 +203,28 @@ namespace SqlSugar
|
|||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
/// <param name="reader"></param>
|
/// <param name="reader"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
public List<T> DataReaderToListNoUsing<T>(IDataReader reader)
|
||||||
|
{
|
||||||
|
var tType = typeof(T);
|
||||||
|
var classProperties = tType.GetProperties().ToList();
|
||||||
|
var reval = new List<T>();
|
||||||
|
if (reader != null && !reader.IsClosed)
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
Dictionary<string, object> result = DataReaderToList(reader, tType, classProperties, reval);
|
||||||
|
var stringValue = SerializeObject(result);
|
||||||
|
reval.Add((T)DeserializeObject<T>(stringValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return reval;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// DataReaderToList
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="reader"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public async Task<List<T>> DataReaderToListAsync<T>(IDataReader reader)
|
public async Task<List<T>> DataReaderToListAsync<T>(IDataReader reader)
|
||||||
{
|
{
|
||||||
using (reader)
|
using (reader)
|
||||||
@ -184,6 +244,28 @@ namespace SqlSugar
|
|||||||
return reval;
|
return reval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// DataReaderToList
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="reader"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<List<T>> DataReaderToListAsyncNoUsing<T>(IDataReader reader)
|
||||||
|
{
|
||||||
|
var tType = typeof(T);
|
||||||
|
var classProperties = tType.GetProperties().ToList();
|
||||||
|
var reval = new List<T>();
|
||||||
|
if (reader != null && !reader.IsClosed)
|
||||||
|
{
|
||||||
|
while (await ((DbDataReader)reader).ReadAsync())
|
||||||
|
{
|
||||||
|
Dictionary<string, object> result = DataReaderToList(reader, tType, classProperties, reval);
|
||||||
|
var stringValue = SerializeObject(result);
|
||||||
|
reval.Add((T)DeserializeObject<T>(stringValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return reval;
|
||||||
|
}
|
||||||
|
|
||||||
private Dictionary<string, object> DataReaderToList<T>(IDataReader reader, Type tType, List<PropertyInfo> classProperties, List<T> reval)
|
private Dictionary<string, object> DataReaderToList<T>(IDataReader reader, Type tType, List<PropertyInfo> classProperties, List<T> reval)
|
||||||
{
|
{
|
||||||
|
@ -14,8 +14,12 @@ namespace SqlSugar
|
|||||||
ExpandoObject DataReaderToExpandoObject(IDataReader reader);
|
ExpandoObject DataReaderToExpandoObject(IDataReader reader);
|
||||||
List<ExpandoObject> DataReaderToExpandoObjectList(IDataReader reader);
|
List<ExpandoObject> DataReaderToExpandoObjectList(IDataReader reader);
|
||||||
Task<List<ExpandoObject>> DataReaderToExpandoObjectListAsync(IDataReader dataReader);
|
Task<List<ExpandoObject>> DataReaderToExpandoObjectListAsync(IDataReader dataReader);
|
||||||
|
List<ExpandoObject> DataReaderToExpandoObjectListNoUsing(IDataReader reader);
|
||||||
|
Task<List<ExpandoObject>> DataReaderToExpandoObjectListAsyncNoUsing(IDataReader dataReader);
|
||||||
List<T> DataReaderToList<T>(IDataReader reader);
|
List<T> DataReaderToList<T>(IDataReader reader);
|
||||||
|
List<T> DataReaderToListNoUsing<T>(IDataReader reader);
|
||||||
Task<List<T>> DataReaderToListAsync<T>(IDataReader dataReader);
|
Task<List<T>> DataReaderToListAsync<T>(IDataReader dataReader);
|
||||||
|
Task<List<T>> DataReaderToListAsyncNoUsing<T>(IDataReader dataReader);
|
||||||
string SerializeObject(object value);
|
string SerializeObject(object value);
|
||||||
string SerializeObject(object value, Type type);
|
string SerializeObject(object value, Type type);
|
||||||
T DeserializeObject<T>(string value);
|
T DeserializeObject<T>(string value);
|
||||||
|
Loading…
Reference in New Issue
Block a user