mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-08 10:24:55 +08:00
-
This commit is contained in:
@@ -19,7 +19,7 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
entytyList =new IDataReaderEntityBuilder<T>(context,dataReader).CreateBuilder(type);
|
||||
entytyList = new IDataReaderEntityBuilder<T>(context, dataReader).CreateBuilder(type);
|
||||
cacheManager.Add(key, entytyList);
|
||||
}
|
||||
List<T> result = new List<T>();
|
||||
@@ -41,44 +41,41 @@ namespace SqlSugar
|
||||
protected List<T> GetKeyValueList<T>(Type type, IDataReader dataReader)
|
||||
{
|
||||
List<T> reval = new List<T>();
|
||||
using (IDataReader re = dataReader)
|
||||
while (dataReader.Read())
|
||||
{
|
||||
while (re.Read())
|
||||
if (UtilConstants.DicOO == type)
|
||||
{
|
||||
if (UtilConstants.DicOO == type)
|
||||
{
|
||||
var kv = new KeyValuePair<object, object>(dataReader.GetValue(0), re.GetValue(1));
|
||||
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<object, object>)));
|
||||
}
|
||||
else if (UtilConstants.DicIS == type)
|
||||
{
|
||||
var kv = new KeyValuePair<int, string>(dataReader.GetValue(0).ObjToInt(), re.GetValue(1).ObjToString());
|
||||
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<int, string>)));
|
||||
}
|
||||
else if (UtilConstants.Dicii == type)
|
||||
{
|
||||
var kv = new KeyValuePair<int, int>(dataReader.GetValue(0).ObjToInt(), re.GetValue(1).ObjToInt());
|
||||
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<int, int>)));
|
||||
}
|
||||
else if (UtilConstants.DicSi == type)
|
||||
{
|
||||
var kv = new KeyValuePair<string, int>(dataReader.GetValue(0).ObjToString(), re.GetValue(1).ObjToInt());
|
||||
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<string, int>)));
|
||||
}
|
||||
else if (UtilConstants.DicSo == type)
|
||||
{
|
||||
var kv = new KeyValuePair<string, object>(dataReader.GetValue(0).ObjToString(), re.GetValue(1));
|
||||
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<string, object>)));
|
||||
}
|
||||
else if (UtilConstants.DicSS == type)
|
||||
{
|
||||
var kv = new KeyValuePair<string, string>(dataReader.GetValue(0).ObjToString(), dataReader.GetValue(1).ObjToString());
|
||||
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<string, string>)));
|
||||
}
|
||||
else
|
||||
{
|
||||
Check.Exception(true, ErrorMessage.NotSupportedDictionary);
|
||||
}
|
||||
var kv = new KeyValuePair<object, object>(dataReader.GetValue(0), dataReader.GetValue(1));
|
||||
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<object, object>)));
|
||||
}
|
||||
else if (UtilConstants.DicIS == type)
|
||||
{
|
||||
var kv = new KeyValuePair<int, string>(dataReader.GetValue(0).ObjToInt(), dataReader.GetValue(1).ObjToString());
|
||||
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<int, string>)));
|
||||
}
|
||||
else if (UtilConstants.Dicii == type)
|
||||
{
|
||||
var kv = new KeyValuePair<int, int>(dataReader.GetValue(0).ObjToInt(), dataReader.GetValue(1).ObjToInt());
|
||||
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<int, int>)));
|
||||
}
|
||||
else if (UtilConstants.DicSi == type)
|
||||
{
|
||||
var kv = new KeyValuePair<string, int>(dataReader.GetValue(0).ObjToString(), dataReader.GetValue(1).ObjToInt());
|
||||
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<string, int>)));
|
||||
}
|
||||
else if (UtilConstants.DicSo == type)
|
||||
{
|
||||
var kv = new KeyValuePair<string, object>(dataReader.GetValue(0).ObjToString(), dataReader.GetValue(1));
|
||||
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<string, object>)));
|
||||
}
|
||||
else if (UtilConstants.DicSS == type)
|
||||
{
|
||||
var kv = new KeyValuePair<string, string>(dataReader.GetValue(0).ObjToString(), dataReader.GetValue(1).ObjToString());
|
||||
reval.Add((T)Convert.ChangeType(kv, typeof(KeyValuePair<string, string>)));
|
||||
}
|
||||
else
|
||||
{
|
||||
Check.Exception(true, ErrorMessage.NotSupportedDictionary);
|
||||
}
|
||||
}
|
||||
return reval;
|
||||
@@ -87,36 +84,33 @@ namespace SqlSugar
|
||||
protected List<T> GetArrayList<T>(Type type, IDataReader dataReader)
|
||||
{
|
||||
List<T> reval = new List<T>();
|
||||
using (IDataReader re = dataReader)
|
||||
int count = dataReader.FieldCount;
|
||||
var childType = type.GetElementType();
|
||||
while (dataReader.Read())
|
||||
{
|
||||
int count = dataReader.FieldCount;
|
||||
var childType = type.GetElementType();
|
||||
while (re.Read())
|
||||
object[] array = new object[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
object[] array = new object[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
array[i] = Convert.ChangeType(re.GetValue(i), childType);
|
||||
}
|
||||
if (childType == UtilConstants.StringType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it.ObjToString()).ToArray(), type));
|
||||
else if (childType == UtilConstants.ObjType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it == DBNull.Value ? null : (object)it).ToArray(), type));
|
||||
else if (childType == UtilConstants.BoolType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it.ObjToBool()).ToArray(), type));
|
||||
else if (childType == UtilConstants.ByteType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it == DBNull.Value ? 0 : (byte)it).ToArray(), type));
|
||||
else if (childType == UtilConstants.DecType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it.ObjToDecimal()).ToArray(), type));
|
||||
else if (childType == UtilConstants.GuidType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it == DBNull.Value ? Guid.Empty : (Guid)it).ToArray(), type));
|
||||
else if (childType == UtilConstants.DateType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it == DBNull.Value ? DateTime.MinValue : (DateTime)it).ToArray(), type));
|
||||
else if (childType == UtilConstants.IntType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it.ObjToInt()).ToArray(), type));
|
||||
else
|
||||
Check.Exception(true, ErrorMessage.NotSupportedArray);
|
||||
array[i] = Convert.ChangeType(dataReader.GetValue(i), childType);
|
||||
}
|
||||
if (childType == UtilConstants.StringType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it.ObjToString()).ToArray(), type));
|
||||
else if (childType == UtilConstants.ObjType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it == DBNull.Value ? null : (object)it).ToArray(), type));
|
||||
else if (childType == UtilConstants.BoolType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it.ObjToBool()).ToArray(), type));
|
||||
else if (childType == UtilConstants.ByteType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it == DBNull.Value ? 0 : (byte)it).ToArray(), type));
|
||||
else if (childType == UtilConstants.DecType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it.ObjToDecimal()).ToArray(), type));
|
||||
else if (childType == UtilConstants.GuidType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it == DBNull.Value ? Guid.Empty : (Guid)it).ToArray(), type));
|
||||
else if (childType == UtilConstants.DateType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it == DBNull.Value ? DateTime.MinValue : (DateTime)it).ToArray(), type));
|
||||
else if (childType == UtilConstants.IntType)
|
||||
reval.Add((T)Convert.ChangeType(array.Select(it => it.ObjToInt()).ToArray(), type));
|
||||
else
|
||||
Check.Exception(true, ErrorMessage.NotSupportedArray);
|
||||
}
|
||||
return reval;
|
||||
}
|
||||
@@ -124,19 +118,16 @@ namespace SqlSugar
|
||||
protected List<T> GetValueTypeList<T>(Type type, IDataReader dataReader)
|
||||
{
|
||||
List<T> reval = new List<T>();
|
||||
using (IDataReader re = dataReader)
|
||||
while (dataReader.Read())
|
||||
{
|
||||
while (re.Read())
|
||||
var value = dataReader.GetValue(0);
|
||||
if (value == DBNull.Value)
|
||||
{
|
||||
var value = re.GetValue(0);
|
||||
if (value == DBNull.Value)
|
||||
{
|
||||
reval.Add(default(T));
|
||||
}
|
||||
else
|
||||
{
|
||||
reval.Add((T)Convert.ChangeType(re.GetValue(0),UtilMethods.GetUnderType(type)));
|
||||
}
|
||||
reval.Add(default(T));
|
||||
}
|
||||
else
|
||||
{
|
||||
reval.Add((T)Convert.ChangeType(dataReader.GetValue(0), UtilMethods.GetUnderType(type)));
|
||||
}
|
||||
}
|
||||
return reval;
|
||||
|
||||
Reference in New Issue
Block a user