|
@ -504,20 +504,39 @@ namespace SqlSugar |
|
|
List<TResult> result = null; |
|
|
List<TResult> result = null; |
|
|
var sqlObj = this.ToSql(); |
|
|
var sqlObj = this.ToSql(); |
|
|
var isComplexModel = QueryBuilder.IsComplexModel(sqlObj.Key); |
|
|
var isComplexModel = QueryBuilder.IsComplexModel(sqlObj.Key); |
|
|
|
|
|
var entityType = typeof(TResult); |
|
|
using (var dataReader = this.Db.GetDataReader(sqlObj.Key, sqlObj.Value.ToArray())) |
|
|
using (var dataReader = this.Db.GetDataReader(sqlObj.Key, sqlObj.Value.ToArray())) |
|
|
{ |
|
|
{ |
|
|
var tType = typeof(TResult); |
|
|
if (entityType.IsAnonymousType() || isComplexModel) |
|
|
if (tType.IsAnonymousType() || isComplexModel) |
|
|
|
|
|
{ |
|
|
{ |
|
|
result = this.Context.RewritableMethods.DataReaderToDynamicList<TResult>(dataReader); |
|
|
result = this.Context.RewritableMethods.DataReaderToDynamicList<TResult>(dataReader); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
result = this.Bind.DataReaderToList<TResult>(tType, dataReader, QueryBuilder.SelectCacheKey); |
|
|
result = this.Bind.DataReaderToList<TResult>(entityType, dataReader, QueryBuilder.SelectCacheKey); |
|
|
} |
|
|
} |
|
|
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection) this.Context.Close(); |
|
|
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection) this.Context.Close(); |
|
|
} |
|
|
} |
|
|
RestoreMapping(); |
|
|
RestoreMapping(); |
|
|
|
|
|
if (result.IsValuable()) |
|
|
|
|
|
{ |
|
|
|
|
|
if (entityType.BaseType.IsValuable() && entityType.BaseType == PubConst.ModelType) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (var item in result) |
|
|
|
|
|
{ |
|
|
|
|
|
var contextProperty=item.GetType().GetProperty("Context"); |
|
|
|
|
|
ConnectionConfig config = new ConnectionConfig(); |
|
|
|
|
|
config =this.Context.CurrentConnectionConfig; |
|
|
|
|
|
var newClient = new SqlSugarClient(config); |
|
|
|
|
|
newClient.MappingColumns = this.Context.MappingColumns; |
|
|
|
|
|
newClient.MappingTables = this.Context.MappingTables; |
|
|
|
|
|
newClient.IgnoreColumns = this.Context.IgnoreColumns; |
|
|
|
|
|
newClient.Ado.MasterConnectionConfig = this.Context.Ado.MasterConnectionConfig; |
|
|
|
|
|
newClient.Ado.SlaveConnectionConfigs = this.Context.Ado.SlaveConnectionConfigs; |
|
|
|
|
|
contextProperty.SetValue(item, newClient, null); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
protected List<string> GetPrimaryKeys() |
|
|
protected List<string> GetPrimaryKeys() |
|
|