Upgrade There is no entity update operation

This commit is contained in:
sunkaixuan 2023-04-20 12:15:14 +08:00
parent 0906ae8ecf
commit e4cc3424c8
6 changed files with 51 additions and 1 deletions

View File

@ -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;

View File

@ -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);

View File

@ -531,6 +531,20 @@ namespace SqlSugar
return this;
}
}
public IUpdateable<T> SetColumns(Expression<Func<T, object>> filedNameExpression, Expression<Func<T, object>> 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)
});
return this;
}
public IUpdateable<T> SetColumns(Expression<Func<T, object>> filedNameExpression, object fieldValue)
{
var name= UpdateBuilder.GetExpressionValue(filedNameExpression,ResolveExpressType.FieldSingle).GetString();

View File

@ -33,7 +33,24 @@ namespace SqlSugar.DbConvert
}
}
public class NoParameterCommonPropertyConvert : ISugarDataConverter
{
public SugarParameter ParameterConverter<T>(object columnValue, int columnIndex)
{
if (columnValue == null)
{
new SugarParameter("null", null, null);
}
return new SugarParameter(columnValue+"", null, null);
}
public T QueryConverter<T>(IDataRecord dr, int i)
{
var value = dr.GetValue(i);
return (T)UtilMethods.ChangeType2(value, typeof(T));
}
}
public class CommonPropertyConvert : ISugarDataConverter
{
public SugarParameter ParameterConverter<T>(object columnValue, int columnIndex)

View File

@ -77,6 +77,7 @@ namespace SqlSugar
IUpdateable<T> SetColumns(string fieldName,object fieldValue);
IUpdateable<T> SetColumns(Expression<Func<T,object>> filedNameExpression, object fieldValue);
IUpdateable<T> SetColumns(Expression<Func<T, object>> filedNameExpression, Expression<Func<T, object>> valueExpression);
IUpdateable<T> SetColumnsIF(bool isUpdateColumns, Expression<Func<T, object>> filedNameExpression, object fieldValue);
IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns,Expression<Func<T, object>> columns);
IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns, params string[] columns);

View File

@ -46,6 +46,8 @@ namespace SqlSugar
internal static Type DicArraySS = typeof(Dictionary<string, string>);
internal static Type DicArraySO = typeof(Dictionary<string, object>);
public static Type SqlConvertType = typeof(SqlSugar.DbConvert.NoParameterCommonPropertyConvert);
public static Type SugarType = typeof(SqlSugarProvider);