Synchronous code

This commit is contained in:
sunkaixuan
2025-07-10 16:52:27 +08:00
parent bd9130a71a
commit 8150e1aa30
5 changed files with 24 additions and 6 deletions

View File

@@ -368,7 +368,7 @@ namespace SqlSugar
var dbColumn = entityInfo.Columns.FirstOrDefault(z => z.PropertyName == it.Key); var dbColumn = entityInfo.Columns.FirstOrDefault(z => z.PropertyName == it.Key);
if (dbColumn == null&&entityInfo.Discrimator==null) if (dbColumn == null&&entityInfo.Discrimator==null)
{ {
Check.ExceptionEasy($"{entityInfo.EntityName} no SugarIndex[ {it.Key} ] found", $"类{entityInfo.EntityName} 索引特性没找到属性名 {it.Key}"); Check.ExceptionEasy($"{entityInfo.EntityName} no SugarIndex[ {it.Key} ] found", $"类{entityInfo.EntityName} 索引特性没找到 {it.Key}");
} }
return new KeyValuePair<string, OrderByType>(dbColumn.DbColumnName, it.Value); return new KeyValuePair<string, OrderByType>(dbColumn.DbColumnName, it.Value);
}) })

View File

@@ -119,6 +119,7 @@ namespace SqlSugar
string tableName = this.Context.EntityMaintenance.GetTableName<T>(); string tableName = this.Context.EntityMaintenance.GetTableName<T>();
var primaryFields = this.GetPrimaryKeys(); var primaryFields = this.GetPrimaryKeys();
var isSinglePrimaryKey = primaryFields.Count == 1; var isSinglePrimaryKey = primaryFields.Count == 1;
var isNvarchar = false;
Check.Exception(primaryFields.IsNullOrEmpty(), string.Format("Table {0} with no primarykey", tableName)); Check.Exception(primaryFields.IsNullOrEmpty(), string.Format("Table {0} with no primarykey", tableName));
if (isSinglePrimaryKey) if (isSinglePrimaryKey)
{ {
@@ -128,6 +129,7 @@ namespace SqlSugar
{ {
var entityPropertyName = this.Context.EntityMaintenance.GetPropertyName<T>(primaryField); var entityPropertyName = this.Context.EntityMaintenance.GetPropertyName<T>(primaryField);
var columnInfo = EntityInfo.Columns.Single(it => it.PropertyName.Equals(entityPropertyName, StringComparison.CurrentCultureIgnoreCase)); var columnInfo = EntityInfo.Columns.Single(it => it.PropertyName.Equals(entityPropertyName, StringComparison.CurrentCultureIgnoreCase));
isNvarchar = columnInfo.SqlParameterDbType is System.Data.DbType dbtype && dbtype == System.Data.DbType.String;
var value = columnInfo.PropertyInfo.GetValue(deleteObj, null); var value = columnInfo.PropertyInfo.GetValue(deleteObj, null);
value = UtilMethods.GetConvertValue(value); value = UtilMethods.GetConvertValue(value);
if (this.Context.CurrentConnectionConfig?.MoreSettings?.TableEnumIsString!=true&& if (this.Context.CurrentConnectionConfig?.MoreSettings?.TableEnumIsString!=true&&
@@ -151,7 +153,15 @@ namespace SqlSugar
} }
else if (primaryKeyValues.Count < 10000) else if (primaryKeyValues.Count < 10000)
{ {
var inValueString = primaryKeyValues.ToArray().ToJoinSqlInVals(); var inValueString = string.Empty;
if (isNvarchar)
{
inValueString = primaryKeyValues.ToArray().ToJoinSqlInValsByVarchar();
}
else
{
inValueString = primaryKeyValues.ToArray().ToJoinSqlInVals();
}
Where(string.Format(DeleteBuilder.WhereInTemplate, SqlBuilder.GetTranslationColumnName(primaryFields.Single()), inValueString)); Where(string.Format(DeleteBuilder.WhereInTemplate, SqlBuilder.GetTranslationColumnName(primaryFields.Single()), inValueString));
} }
else else

View File

@@ -124,10 +124,14 @@ namespace SqlSugar
{ {
continue; continue;
} }
if (item.SqlParameterDbType is Type) if (item.SqlParameterDbType is Type)
{ {
continue; continue;
} }
else if (item.SqlParameterDbType is System.Data.DbType dbtype)
{
paramters.DbType = dbtype;
}
if (item.IsJson) if (item.IsJson)
{ {
paramters.IsJson = true; paramters.IsJson = true;

View File

@@ -217,7 +217,7 @@ namespace SqlSugar
public virtual object FormatValue(object value) public virtual object FormatValue(object value)
{ {
var N = "N"; var N = "N";
if (this.Context.CurrentConnectionConfig.DbType == DbType.Sqlite) if (this.Context.CurrentConnectionConfig.DbType == DbType.Sqlite)
{ {
N = ""; N = "";
} }

View File

@@ -6,7 +6,7 @@ using System.Linq.Expressions;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SqlSugar namespace SqlSugar
{ {
@@ -514,13 +514,17 @@ namespace SqlSugar
if (item.SqlParameterDbType is Type) if (item.SqlParameterDbType is Type)
{ {
continue; continue;
} }
var parameter = new SugarParameter(this.SqlBuilder.SqlParameterKeyWord + item.DbColumnName, item.Value, item.PropertyType); var parameter = new SugarParameter(this.SqlBuilder.SqlParameterKeyWord + item.DbColumnName, item.Value, item.PropertyType);
if (item.IsJson) if (item.IsJson)
{ {
parameter.IsJson = true; parameter.IsJson = true;
SqlBuilder.ChangeJsonType(parameter); SqlBuilder.ChangeJsonType(parameter);
} }
if (item.SqlParameterDbType is System.Data.DbType dbtype)
{
parameter.DbType = dbtype;
}
if (item.IsArray) if (item.IsArray)
{ {
parameter.IsArray = true; parameter.IsArray = true;