diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/InsertBuilder.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/InsertBuilder.cs index 73af85dd9..631cfebfb 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/InsertBuilder.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/InsertBuilder.cs @@ -287,6 +287,14 @@ namespace SqlSugar { return columnInfo.InsertSql; } + else if (columnInfo.SqlParameterDbType is Type && (Type)columnInfo.SqlParameterDbType == UtilConstants.SqlConvertType) + { + var type = columnInfo.SqlParameterDbType as Type; + var ParameterConverter = type.GetMethod("ParameterConverter").MakeGenericMethod(typeof(string)); + var obj = Activator.CreateInstance(type); + var p = ParameterConverter.Invoke(obj, new object[] { columnInfo.Value, GetDbColumnIndex }) as SugarParameter; + return p.ParameterName; + } else if (columnInfo.SqlParameterDbType is Type) { var type=columnInfo.SqlParameterDbType as Type; diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/UpdateBuilder.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/UpdateBuilder.cs index 19ec844a1..f845f5397 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/UpdateBuilder.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/UpdateBuilder.cs @@ -402,7 +402,15 @@ namespace SqlSugar { return columnInfo.UpdateSql; } - else if (columnInfo.SqlParameterDbType is Type) + else if (columnInfo.SqlParameterDbType is Type&& (Type)columnInfo.SqlParameterDbType == UtilConstants.SqlConvertType) + { + var type = columnInfo.SqlParameterDbType as Type; + var ParameterConverter = type.GetMethod("ParameterConverter").MakeGenericMethod(typeof(string)); + var obj = Activator.CreateInstance(type); + var p = ParameterConverter.Invoke(obj, new object[] { columnInfo.Value, GetDbColumnIndex }) as SugarParameter; + return p.ParameterName; + } + else if (columnInfo.SqlParameterDbType is Type) { var type = columnInfo.SqlParameterDbType as Type; var ParameterConverter = type.GetMethod("ParameterConverter").MakeGenericMethod(columnInfo.PropertyType); diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs index f4c78380b..eb2bf1757 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs @@ -531,6 +531,21 @@ namespace SqlSugar return this; } } + public IUpdateable SetColumns(Expression> filedNameExpression, Expression> valueExpression) + { + var name = UpdateBuilder.GetExpressionValue(filedNameExpression, ResolveExpressType.FieldSingle).GetString(); + name = UpdateBuilder.Builder.GetNoTranslationColumnName(name); + var value = UpdateBuilder.GetExpressionValue(valueExpression, ResolveExpressType.FieldSingle).GetString(); + this.UpdateBuilder.DbColumnInfoList.Add(new DbColumnInfo() + { + DbColumnName = name, + Value = value, + PropertyName = name , + SqlParameterDbType=typeof(SqlSugar.DbConvert.NoParameterCommonPropertyConvert) + }); + this.UpdateBuilder.SetValues.Add(new KeyValuePair(name,value)); + return this; + } public IUpdateable SetColumns(Expression> filedNameExpression, object fieldValue) { var name= UpdateBuilder.GetExpressionValue(filedNameExpression,ResolveExpressType.FieldSingle).GetString(); diff --git a/Src/Asp.NetCore2/SqlSugar/Entities/DefaultCustom.cs b/Src/Asp.NetCore2/SqlSugar/Entities/DefaultCustom.cs index 8341d9490..34e101ea9 100644 --- a/Src/Asp.NetCore2/SqlSugar/Entities/DefaultCustom.cs +++ b/Src/Asp.NetCore2/SqlSugar/Entities/DefaultCustom.cs @@ -33,7 +33,24 @@ namespace SqlSugar.DbConvert } } + public class NoParameterCommonPropertyConvert : ISugarDataConverter + { + public SugarParameter ParameterConverter(object columnValue, int columnIndex) + { + if (columnValue == null) + { + new SugarParameter("null", null, null); + } + return new SugarParameter(columnValue+"", null, null); + } + public T QueryConverter(IDataRecord dr, int i) + { + + var value = dr.GetValue(i); + return (T)UtilMethods.ChangeType2(value, typeof(T)); + } + } public class CommonPropertyConvert : ISugarDataConverter { public SugarParameter ParameterConverter(object columnValue, int columnIndex) diff --git a/Src/Asp.NetCore2/SqlSugar/Interface/IUpdateable.cs b/Src/Asp.NetCore2/SqlSugar/Interface/IUpdateable.cs index 182c4cb65..979c0ba43 100644 --- a/Src/Asp.NetCore2/SqlSugar/Interface/IUpdateable.cs +++ b/Src/Asp.NetCore2/SqlSugar/Interface/IUpdateable.cs @@ -77,6 +77,7 @@ namespace SqlSugar IUpdateable SetColumns(string fieldName,object fieldValue); IUpdateable SetColumns(Expression> filedNameExpression, object fieldValue); + IUpdateable SetColumns(Expression> filedNameExpression, Expression> valueExpression); IUpdateable SetColumnsIF(bool isUpdateColumns, Expression> filedNameExpression, object fieldValue); IUpdateable UpdateColumnsIF(bool isUpdateColumns,Expression> columns); IUpdateable UpdateColumnsIF(bool isUpdateColumns, params string[] columns); diff --git a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilConstants.cs b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilConstants.cs index d2715d286..000e72d64 100644 --- a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilConstants.cs +++ b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilConstants.cs @@ -46,6 +46,8 @@ namespace SqlSugar internal static Type DicArraySS = typeof(Dictionary); internal static Type DicArraySO = typeof(Dictionary); + public static Type SqlConvertType = typeof(SqlSugar.DbConvert.NoParameterCommonPropertyConvert); + public static Type SugarType = typeof(SqlSugarProvider);