mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-08 02:14:53 +08:00
-
This commit is contained in:
@@ -435,8 +435,8 @@ namespace SqlSugar
|
||||
var tableName = this.SqlBuilder.GetPackTable(sql, "MergeTable");
|
||||
var mergeQueryable = this.Context.Queryable<ExpandoObject>();
|
||||
mergeQueryable.QueryBuilder.Parameters = QueryBuilder.Parameters;
|
||||
mergeQueryable.QueryBuilder.WhereIndex = QueryBuilder.WhereIndex+1;
|
||||
mergeQueryable.QueryBuilder.JoinIndex = QueryBuilder.JoinIndex+1;
|
||||
mergeQueryable.QueryBuilder.WhereIndex = QueryBuilder.WhereIndex + 1;
|
||||
mergeQueryable.QueryBuilder.JoinIndex = QueryBuilder.JoinIndex + 1;
|
||||
return mergeQueryable.AS(tableName).Select<T>("*");
|
||||
}
|
||||
|
||||
@@ -590,13 +590,13 @@ namespace SqlSugar
|
||||
RestoreMapping();
|
||||
return new KeyValuePair<string, List<SugarParameter>>(sql, QueryBuilder.Parameters);
|
||||
}
|
||||
public ISugarQueryable<T> WithCache(int cacheDurationInSeconds = int.MaxValue)
|
||||
public ISugarQueryable<T> WithCache(int cacheDurationInSeconds = int.MaxValue)
|
||||
{
|
||||
this.IsCache = true;
|
||||
this.CacheTime = cacheDurationInSeconds;
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
|
||||
public ISugarQueryable<T> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
|
||||
{
|
||||
if (IsCache)
|
||||
{
|
||||
@@ -1014,24 +1014,21 @@ namespace SqlSugar
|
||||
return result;
|
||||
}
|
||||
|
||||
protected List<TResult> GetData<TResult>(KeyValuePair<string, List<SugarParameter>> sqlObj, bool isComplexModel, Type entityType)
|
||||
protected List<TResult> GetData<TResult>(KeyValuePair<string, List<SugarParameter>> sqlObj, bool isComplexModel, Type entityType)
|
||||
{
|
||||
List<TResult> result;
|
||||
using (var dataReader = this.Db.GetDataReader(sqlObj.Key, sqlObj.Value.ToArray()))
|
||||
var dataReader = this.Db.GetDataReader(sqlObj.Key, sqlObj.Value.ToArray());
|
||||
if (typeof(TResult) == typeof(ExpandoObject))
|
||||
{
|
||||
if (typeof(TResult) == typeof(ExpandoObject))
|
||||
{
|
||||
result = this.Context.Utilities.DataReaderToExpandoObjectList(dataReader) as List<TResult>;
|
||||
|
||||
}
|
||||
else if (entityType.IsAnonymousType() || isComplexModel)
|
||||
{
|
||||
result = this.Context.Utilities.DataReaderToDynamicList<TResult>(dataReader);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = this.Bind.DataReaderToList<TResult>(entityType, dataReader, QueryBuilder.SelectCacheKey);
|
||||
}
|
||||
result = this.Context.Utilities.DataReaderToExpandoObjectList(dataReader) as List<TResult>;
|
||||
}
|
||||
else if (entityType.IsAnonymousType() || isComplexModel)
|
||||
{
|
||||
result = this.Context.Utilities.DataReaderToDynamicList<TResult>(dataReader);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = this.Bind.DataReaderToList<TResult>(entityType, dataReader, QueryBuilder.SelectCacheKey);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1203,7 +1200,7 @@ namespace SqlSugar
|
||||
public new ISugarQueryable<T, T2> OrderByIF(bool isOrderBy, Expression<Func<T, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression,type);
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2> OrderByIF(bool isOrderBy, Expression<Func<T, T2, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
@@ -4677,12 +4674,13 @@ namespace SqlSugar
|
||||
base.With(withString);
|
||||
return this;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> WithCache(int cacheDurationInSeconds=int.MaxValue) {
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> WithCache(int cacheDurationInSeconds = int.MaxValue)
|
||||
{
|
||||
this.IsCache = true;
|
||||
this.CacheTime = cacheDurationInSeconds;
|
||||
return this;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> WithCacheIF(bool isCache,int cacheDurationInSeconds = int.MaxValue)
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
|
||||
{
|
||||
if (IsCache)
|
||||
{
|
||||
|
||||
@@ -46,15 +46,18 @@ namespace SqlSugar
|
||||
/// <returns></returns>
|
||||
public List<ExpandoObject> DataReaderToExpandoObjectList(IDataReader reader)
|
||||
{
|
||||
List<ExpandoObject> result = new List<ExpandoObject>();
|
||||
if (reader != null && !reader.IsClosed)
|
||||
using (reader)
|
||||
{
|
||||
while (reader.Read())
|
||||
List<ExpandoObject> result = new List<ExpandoObject>();
|
||||
if (reader != null && !reader.IsClosed)
|
||||
{
|
||||
result.Add(DataReaderToExpandoObject(reader));
|
||||
while (reader.Read())
|
||||
{
|
||||
result.Add(DataReaderToExpandoObject(reader));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -90,68 +93,70 @@ namespace SqlSugar
|
||||
/// <returns></returns>
|
||||
public List<T> DataReaderToDynamicList<T>(IDataReader reader)
|
||||
{
|
||||
var tType = typeof(T);
|
||||
var classProperties = tType.GetProperties().ToList();
|
||||
var reval = new List<T>();
|
||||
if (reader != null && !reader.IsClosed)
|
||||
using (reader)
|
||||
{
|
||||
while (reader.Read())
|
||||
var tType = typeof(T);
|
||||
var classProperties = tType.GetProperties().ToList();
|
||||
var reval = new List<T>();
|
||||
if (reader != null && !reader.IsClosed)
|
||||
{
|
||||
var readerValues = DataReaderToDictionary(reader);
|
||||
var result = new Dictionary<string, object>();
|
||||
foreach (var item in classProperties)
|
||||
while (reader.Read())
|
||||
{
|
||||
var name = item.Name;
|
||||
var typeName = tType.Name;
|
||||
if (item.PropertyType.IsClass())
|
||||
var readerValues = DataReaderToDictionary(reader);
|
||||
var result = new Dictionary<string, object>();
|
||||
foreach (var item in classProperties)
|
||||
{
|
||||
result.Add(name, DataReaderToDynamicList_Part(readerValues, item, reval));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (readerValues.ContainsKey(name))
|
||||
var name = item.Name;
|
||||
var typeName = tType.Name;
|
||||
if (item.PropertyType.IsClass())
|
||||
{
|
||||
var addValue = readerValues[name];
|
||||
if (addValue == DBNull.Value)
|
||||
result.Add(name, DataReaderToDynamicList_Part(readerValues, item, reval));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (readerValues.ContainsKey(name))
|
||||
{
|
||||
if (item.PropertyType.IsIn(UtilConstants.IntType, UtilConstants.DecType, UtilConstants.DobType, UtilConstants.ByteType))
|
||||
var addValue = readerValues[name];
|
||||
if (addValue == DBNull.Value)
|
||||
{
|
||||
addValue = 0;
|
||||
}
|
||||
else if (item.PropertyType == UtilConstants.GuidType)
|
||||
{
|
||||
addValue = Guid.Empty;
|
||||
}
|
||||
else if (item.PropertyType == UtilConstants.DateType)
|
||||
{
|
||||
addValue = DateTime.MinValue;
|
||||
}
|
||||
else if (item.PropertyType == UtilConstants.StringType)
|
||||
{
|
||||
addValue = null;
|
||||
if (item.PropertyType.IsIn(UtilConstants.IntType, UtilConstants.DecType, UtilConstants.DobType, UtilConstants.ByteType))
|
||||
{
|
||||
addValue = 0;
|
||||
}
|
||||
else if (item.PropertyType == UtilConstants.GuidType)
|
||||
{
|
||||
addValue = Guid.Empty;
|
||||
}
|
||||
else if (item.PropertyType == UtilConstants.DateType)
|
||||
{
|
||||
addValue = DateTime.MinValue;
|
||||
}
|
||||
else if (item.PropertyType == UtilConstants.StringType)
|
||||
{
|
||||
addValue = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
addValue = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
addValue = null;
|
||||
if (item.PropertyType == UtilConstants.IntType)
|
||||
{
|
||||
addValue = Convert.ToInt32(addValue);
|
||||
}
|
||||
}
|
||||
result.Add(name, addValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.PropertyType == UtilConstants.IntType)
|
||||
{
|
||||
addValue = Convert.ToInt32(addValue);
|
||||
}
|
||||
}
|
||||
result.Add(name, addValue);
|
||||
}
|
||||
}
|
||||
var stringValue = SerializeObject(result);
|
||||
reval.Add((T)DeserializeObject<T>(stringValue));
|
||||
}
|
||||
var stringValue = SerializeObject(result);
|
||||
reval.Add((T)DeserializeObject<T>(stringValue));
|
||||
}
|
||||
reader.Close();
|
||||
return reval;
|
||||
}
|
||||
return reval;
|
||||
}
|
||||
|
||||
private Dictionary<string, object> DataReaderToDynamicList_Part<T>(Dictionary<string, object> readerValues, PropertyInfo item, List<T> reval)
|
||||
|
||||
Reference in New Issue
Block a user