优化DR连接

Optimize the DR connection
This commit is contained in:
sunkaixuan
2017-06-13 19:06:37 +08:00
parent a0f028747a
commit 29efa042e4
3 changed files with 5 additions and 4 deletions

View File

@@ -59,11 +59,12 @@ namespace OrmTest.Demo
private static void Tran()
{
var db = GetInstance();
var x=db.Insertable(new Student() { CreateTime = DateTime.Now, Name = "tran" }).ExecuteCommand();
//1. no result
var result = db.Ado.UseTran(() =>
{
var beginCount = db.Queryable<Student>().Count();
var beginCount = db.Queryable<Student>().ToList();
db.Ado.ExecuteCommand("delete student");
var endCount = db.Queryable<Student>().Count();
throw new Exception("error haha");

View File

@@ -223,7 +223,8 @@ namespace SqlSugar
{
ExecuteBefore(sql, parameters);
IDbCommand sqlCommand = GetCommand(sql, parameters);
IDataReader sqlDataReader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
var isAutoClose = this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Transaction == null;
IDataReader sqlDataReader = sqlCommand.ExecuteReader(isAutoClose?CommandBehavior.CloseConnection:CommandBehavior.Default);
if (this.IsClearParameters)
sqlCommand.Parameters.Clear();
ExecuteAfter(sql, parameters);

View File

@@ -566,7 +566,6 @@ namespace SqlSugar
{
result = this.Bind.DataReaderToList<TResult>(entityType, dataReader, QueryBuilder.SelectCacheKey);
}
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection) this.Context.Close();
}
RestoreMapping();
SetContextModel(result, entityType);