mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-27 06:35:49 +08:00
优化DR连接
Optimize the DR connection
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user