Skip to content

Commit

Permalink
v2.0.8 更新内容:1. 新增:IDbSession接口增加SetCommandType方法,以支持调用存储过程 2. 优化:删除重复…
Browse files Browse the repository at this point in the history
…的OnExecuting调用 3. 新增:IDbSession接口新增查询并返回DataTable的方法 4. 新增:IDbSession接口增加设置Dapper参数的方法SetCommandTimeout和SetBuffered
  • Loading branch information
0611163 committed Dec 8, 2023
1 parent 196f55a commit ff16d1a
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 74 deletions.
11 changes: 7 additions & 4 deletions Dapper.Lite/Dapper.Lite/Dapper.Lite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<Nullable>disable</Nullable>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>Dapper.Lite</Title>
<AssemblyVersion>2.0.7</AssemblyVersion>
<FileVersion>2.0.7</FileVersion>
<Version>2.0.7</Version>
<AssemblyVersion>2.0.8</AssemblyVersion>
<FileVersion>2.0.8</FileVersion>
<Version>2.0.8</Version>
<PackageId>Dapper.Lite</PackageId>
<PackageProjectUrl>https://github.com/0611163/Dapper.Lite</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand All @@ -20,7 +20,10 @@
</Description>
<PackageReleaseNotes>
更新内容:
1. 移除接口的where T : new()限制,以支持QueryList<string>
1. 新增:IDbSession接口增加SetCommandType方法,以支持调用存储过程
2. 优化:删除重复的OnExecuting调用
3. 新增:IDbSession接口新增查询并返回DataTable的方法
4. 新增:IDbSession接口增加设置Dapper参数的方法SetCommandTimeout和SetBuffered
</PackageReleaseNotes>
</PropertyGroup>

Expand Down
37 changes: 37 additions & 0 deletions Dapper.Lite/Dapper.Lite/Session/DbSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public partial class DbSession : IDbSession
/// </summary>
public DbConnection Conn => _tran?.Connection;

private CommandType _commandType = CommandType.Text;

private int? _commandTimeout = null; // Dapper参数

private bool _buffered = true; // Dapper参数

#endregion

#region 静态构造函数
Expand Down Expand Up @@ -254,5 +260,36 @@ public async Task<DbConnection> GetOpenedConnectionAsync(DbTransaction tran = nu
}
#endregion

#region 设置CommandType
/// <summary>
/// 设置CommandType
/// </summary>
public IDbSession SetCommandType(CommandType commandType)
{
_commandType = commandType;
return this;
}
#endregion

#region Dapper参数设置
/// <summary>
/// 设置Dapper参数commandTimeout
/// </summary>
public IDbSession SetCommandTimeout(int? commandTimeout)
{
_commandTimeout = commandTimeout;
return this;
}

/// <summary>
/// 设置Dapper参数buffered
/// </summary>
public IDbSession SetBuffered(bool buffered)
{
_buffered = buffered;
return this;
}
#endregion

}
}
16 changes: 0 additions & 16 deletions Dapper.Lite/Dapper.Lite/Session/DbSessionDelete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public int DeleteById<T>(string id)
Tuple<string, string> delTmpl = _provider.CreateDeleteSqlTempldate();
sbSql.Append(string.Format(delTmpl.Item1 + " {0} " + delTmpl.Item2 + " {1}={2}", GetTableName(_provider, type), idNameWithQuote, _provider.GetParameterName(idName, idType)));

OnExecuting?.Invoke(sbSql.ToString(), cmdParms);

return Execute(sbSql.ToString(), cmdParms);
}
#endregion
Expand Down Expand Up @@ -90,8 +88,6 @@ public async Task<int> DeleteByIdAsync<T>(string id)
Tuple<string, string> delTmpl = _provider.CreateDeleteSqlTempldate();
sbSql.Append(string.Format(delTmpl.Item1 + " {0} " + delTmpl.Item2 + " {1}={2}", GetTableName(_provider, type), idNameWithQuote, _provider.GetParameterName(idName, idType)));

OnExecuting?.Invoke(sbSql.ToString(), cmdParms);

return await ExecuteAsync(sbSql.ToString(), cmdParms);
}
#endregion
Expand Down Expand Up @@ -122,8 +118,6 @@ public int BatchDeleteByIds<T>(string ids)
sbSql.Remove(sbSql.Length - 1, 1);
sbSql.Append(")");

OnExecuting?.Invoke(sbSql.ToString(), cmdParms);

return Execute(sbSql.ToString(), cmdParms);
}
#endregion
Expand Down Expand Up @@ -153,8 +147,6 @@ public async Task<int> BatchDeleteByIdsAsync<T>(string ids)
sbSql.Remove(sbSql.Length - 1, 1);
sbSql.Append(")");

OnExecuting?.Invoke(sbSql.ToString(), cmdParms);

return await ExecuteAsync(sbSql.ToString(), cmdParms);
}
#endregion
Expand Down Expand Up @@ -200,8 +192,6 @@ public int DeleteByCondition(Type type, string condition)
Tuple<string, string> delTmpl = _provider.CreateDeleteSqlTempldate();
sbSql.Append(string.Format(delTmpl.Item1 + " {0} " + delTmpl.Item2 + " {1}", GetTableName(_provider, type), condition));

OnExecuting?.Invoke(sbSql.ToString(), null);

return Execute(sbSql.ToString());
}
#endregion
Expand All @@ -219,8 +209,6 @@ public async Task<int> DeleteByConditionAsync(Type type, string condition)
Tuple<string, string> delTmpl = _provider.CreateDeleteSqlTempldate();
sbSql.Append(string.Format(delTmpl.Item1 + " {0} " + delTmpl.Item2 + " {1}", GetTableName(_provider, type), condition));

OnExecuting?.Invoke(sbSql.ToString(), null);

return await ExecuteAsync(sbSql.ToString());
}
#endregion
Expand Down Expand Up @@ -265,8 +253,6 @@ public int DeleteByCondition(Type type, string condition, DbParameter[] cmdParms
Tuple<string, string> delTmpl = _provider.CreateDeleteSqlTempldate();
sbSql.Append(string.Format(delTmpl.Item1 + " {0} " + delTmpl.Item2 + " {1}", GetTableName(_provider, type), condition));

OnExecuting?.Invoke(sbSql.ToString(), cmdParms);

return Execute(sbSql.ToString(), cmdParms);
}
#endregion
Expand All @@ -284,8 +270,6 @@ public async Task<int> DeleteByConditionAsync(Type type, string condition, DbPar
Tuple<string, string> delTmpl = _provider.CreateDeleteSqlTempldate();
sbSql.Append(string.Format(delTmpl.Item1 + " {0} " + delTmpl.Item2 + " {1}", GetTableName(_provider, type), condition));

OnExecuting?.Invoke(sbSql.ToString(), cmdParms);

return await ExecuteAsync(sbSql.ToString(), cmdParms);
}
#endregion
Expand Down
Loading

0 comments on commit ff16d1a

Please sign in to comment.