This commit is contained in:
sunkaixuan
2017-04-30 19:20:02 +08:00
parent 3a7309a854
commit ec65a93511
4 changed files with 14 additions and 4 deletions

View File

@@ -12,10 +12,12 @@ namespace OrmTest.UnitTest
{
public void Init()
{
using (var db = GetInstance())
var db = GetInstance();
for (int i = 0; i < 200; i++)
{
var x= db.Queryable<Student>().ToList();
var x = db.Queryable<Student>().ToList();
}
}
public SqlSugarClient GetInstance()
{

View File

@@ -173,6 +173,7 @@ namespace SqlSugar
{
this.Transaction.Commit();
this.Transaction = null;
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection) this.Close();
}
}
public virtual void CommitTran()
@@ -181,6 +182,7 @@ namespace SqlSugar
{
this.Transaction.Commit();
this.Transaction = null;
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection) this.Close();
}
}
public abstract IDataParameter[] ToIDbDataParameter(params SugarParameter[] pars);
@@ -201,6 +203,7 @@ namespace SqlSugar
if (this.IsClearParameters)
sqlCommand.Parameters.Clear();
ExecLogEvent(sql, pars, false);
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection&&this.Transaction==null) this.Close();
return count;
}
public virtual IDataReader GetDataReader(string sql, params SugarParameter[] pars)
@@ -226,6 +229,7 @@ namespace SqlSugar
if (this.IsClearParameters)
sqlCommand.Parameters.Clear();
ExecLogEvent(sql, pars, false);
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Transaction == null) this.Close();
return ds;
}
public virtual object GetScalar(string sql, params SugarParameter[] pars)
@@ -238,6 +242,7 @@ namespace SqlSugar
if (this.IsClearParameters)
sqlCommand.Parameters.Clear();
ExecLogEvent(sql, pars, false);
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Transaction == null) this.Close();
return scalar;
}
#endregion

View File

@@ -587,6 +587,7 @@ namespace SqlSugar
}
private List<TResult> _ToList<TResult>()
{
List<TResult> result = null;
var sqlObj = this.ToSql();
var isComplexModel = QueryBuilder.IsComplexModel(sqlObj.Key);
using (var dataReader = this.Db.GetDataReader(sqlObj.Key, sqlObj.Value.ToArray()))
@@ -594,14 +595,15 @@ namespace SqlSugar
var tType = typeof(TResult);
if (tType.IsAnonymousType() || isComplexModel)
{
return this.Context.RewritableMethods.DataReaderToDynamicList<TResult>(dataReader);
result= this.Context.RewritableMethods.DataReaderToDynamicList<TResult>(dataReader);
}
else
{
var reval = this.Bind.DataReaderToList<TResult>(tType, dataReader, QueryBuilder.SelectCacheKey);
return reval;
}
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection) this.Context.Close();
}
return result;
}
#endregion
}

View File

@@ -230,6 +230,7 @@ namespace SqlSugar
using (var dataReader = this.Database.GetDataReader(sql, dbPars))
{
var reval = this.Database.DbBind.DataReaderToList<T>(typeof(T), dataReader, builder.SqlQueryBuilder.Fields);
if (this.CurrentConnectionConfig.IsAutoCloseConnection) this.Close();
builder.SqlQueryBuilder.Clear();
return reval;
}