diff --git a/Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs b/Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs index 9703bf32c..6bdcb014f 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs @@ -281,6 +281,7 @@ namespace SqlSugar column.IsOnlyIgnoreUpdate = sugarColumn.IsOnlyIgnoreUpdate; column.IsArray = sugarColumn.IsArray; column.IsTreeKey = sugarColumn.IsTreeKey; + column.SqlParameterDbType = sugarColumn.SqlParameterDbType; } else { diff --git a/Src/Asp.Net/SqlSugar/Entities/EntityColumnInfo.cs b/Src/Asp.Net/SqlSugar/Entities/EntityColumnInfo.cs index 80ef3a714..6f6627677 100644 --- a/Src/Asp.Net/SqlSugar/Entities/EntityColumnInfo.cs +++ b/Src/Asp.Net/SqlSugar/Entities/EntityColumnInfo.cs @@ -21,6 +21,7 @@ namespace SqlSugar public bool IsPrimarykey { get; set; } public bool IsTreeKey { get; set; } public bool IsEnableUpdateVersionValidation { get; set; } + public object SqlParameterDbType { get; set; } public string EntityName { get; set; } public string DbTableName { get; set; } public bool IsIgnore { get; set; } diff --git a/Src/Asp.Net/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs b/Src/Asp.Net/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs index ce2e87111..145504385 100644 --- a/Src/Asp.Net/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs +++ b/Src/Asp.Net/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs @@ -196,6 +196,8 @@ namespace SqlSugar get { return _IsTreeKey; } set { _IsTreeKey = value; } } + + public object SqlParameterDbType { get; set; } } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs index 636982de4..8d331ef00 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs @@ -170,7 +170,15 @@ namespace SqlSugar + Context.ParameterIndex; if (value.ObjToString() != "NULL" && !parameter.ValueIsNull) { - this.Context.Parameters.Add(new SugarParameter(appendValue, value)); + EntityColumnInfo columnInfo = GetColumnInfo(oppoSiteExpression); + if (columnInfo != null && columnInfo.SqlParameterDbType != null&& columnInfo.SqlParameterDbType is System.Data.DbType) + { + this.Context.Parameters.Add(new SugarParameter(appendValue, value, (System.Data.DbType)columnInfo.SqlParameterDbType)); + } + else + { + this.Context.Parameters.Add(new SugarParameter(appendValue, value)); + } } else { @@ -251,6 +259,19 @@ namespace SqlSugar } } } + + private EntityColumnInfo GetColumnInfo(Expression oppoSiteExpression) + { + var oppsite = (oppoSiteExpression as MemberExpression); + if (oppsite == null) return null; + if (this.Context.SugarContext == null) return null; + if (this.Context.SugarContext.Context == null) return null; + if (oppsite.Expression == null) return null; + var columnInfo = this.Context.SugarContext.Context.EntityMaintenance + .GetEntityInfo(oppsite.Expression.Type).Columns.FirstOrDefault(it => it.PropertyName == oppsite.Member.Name); + return columnInfo; + } + protected void AppendOpreator(ExpressionParameter parameter, bool? isLeft) { if (isLeft == true)