This commit is contained in:
nsnail 2022-12-27 16:14:38 +08:00
parent 8c1083f732
commit f3d0f98970

View File

@ -1,7 +1,7 @@
namespace NSExt.Extensions; namespace NSExt.Extensions;
/// <summary> /// <summary>
/// DbCommandExtensions /// DbCommandExtensions
/// </summary> /// </summary>
public static class DbCommandExtensions public static class DbCommandExtensions
{ {
@ -15,30 +15,18 @@ public static class DbCommandExtensions
//应逆向替换,否则由于 多个表的过滤器问题导致替换不完整 如 @TenantId1 @TenantId10 //应逆向替换,否则由于 多个表的过滤器问题导致替换不完整 如 @TenantId1 @TenantId10
for (var i = me.Parameters.Count - 1; i >= 0; i--) { for (var i = me.Parameters.Count - 1; i >= 0; i--) {
#pragma warning disable IDE0072
sql = me.Parameters[i].DbType switch { sql = me.Parameters[i].DbType switch {
#pragma warning restore IDE0072
DbType.String or DbType.DateTime or DbType.Date or DbType.Time or DbType.DateTime2 DbType.String or DbType.DateTime or DbType.Date or DbType.Time or DbType.DateTime2
or DbType.DateTimeOffset or DbType.Guid or DbType.VarNumeric or DbType.AnsiStringFixedLength or DbType.DateTimeOffset or DbType.Guid or DbType.VarNumeric or DbType.AnsiStringFixedLength
or DbType.AnsiString or DbType.StringFixedLength => sql.Replace( // or DbType.AnsiString
me.Parameters[i].ParameterName, "'" + me.Parameters[i].Value + "'") or DbType.StringFixedLength =>
, DbType.Boolean => sql.Replace( // sql.Replace(me.Parameters[i].ParameterName, "'" + me.Parameters[i].Value + "'")
me.Parameters[i].ParameterName , DbType.Boolean => sql.Replace(//
, Convert.ToBoolean(me.Parameters[i].Value, CultureInfo.InvariantCulture) ? "1" : "0") me.Parameters[i].ParameterName
, DbType.Binary => throw new NotImplementedException() , Convert.ToBoolean(me.Parameters[i].Value, CultureInfo.InvariantCulture) ? "1" : "0")
, DbType.Byte => throw new NotImplementedException() , _ => sql.Replace(me.Parameters[i].ParameterName, me.Parameters[i].Value?.ToString())
, DbType.Currency => throw new NotImplementedException()
, DbType.Decimal => throw new NotImplementedException()
, DbType.Double => throw new NotImplementedException()
, DbType.Int16 => throw new NotImplementedException()
, DbType.Int32 => throw new NotImplementedException()
, DbType.Int64 => throw new NotImplementedException()
, DbType.Object => throw new NotImplementedException()
, DbType.SByte => throw new NotImplementedException()
, DbType.Single => throw new NotImplementedException()
, DbType.UInt16 => throw new NotImplementedException()
, DbType.UInt32 => throw new NotImplementedException()
, DbType.UInt64 => throw new NotImplementedException()
, DbType.Xml => throw new NotImplementedException()
, _ => sql.Replace(me.Parameters[i].ParameterName, me.Parameters[i].Value?.ToString())
}; };
} }