Browse Source

Synchronization code

pull/32/head
sunkaixuan 2 years ago
parent
commit
9c82190169
  1. 8
      Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/InsertBuilder.cs
  2. 10
      Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/UpdateBuilder.cs
  3. 15
      Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs
  4. 17
      Src/Asp.NetCore2/SqlSugar/Entities/DefaultCustom.cs
  5. 1
      Src/Asp.NetCore2/SqlSugar/Interface/IUpdateable.cs
  6. 2
      Src/Asp.NetCore2/SqlSugar/Utilities/UtilConstants.cs

8
Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/InsertBuilder.cs

@ -287,6 +287,14 @@ namespace SqlSugar
{ {
return columnInfo.InsertSql; 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) else if (columnInfo.SqlParameterDbType is Type)
{ {
var type=columnInfo.SqlParameterDbType as Type; var type=columnInfo.SqlParameterDbType as Type;

10
Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/UpdateBuilder.cs

@ -402,7 +402,15 @@ namespace SqlSugar
{ {
return columnInfo.UpdateSql; 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 type = columnInfo.SqlParameterDbType as Type;
var ParameterConverter = type.GetMethod("ParameterConverter").MakeGenericMethod(columnInfo.PropertyType); var ParameterConverter = type.GetMethod("ParameterConverter").MakeGenericMethod(columnInfo.PropertyType);

15
Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs

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

17
Src/Asp.NetCore2/SqlSugar/Entities/DefaultCustom.cs

@ -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 class CommonPropertyConvert : ISugarDataConverter
{ {
public SugarParameter ParameterConverter<T>(object columnValue, int columnIndex) public SugarParameter ParameterConverter<T>(object columnValue, int columnIndex)

1
Src/Asp.NetCore2/SqlSugar/Interface/IUpdateable.cs

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

2
Src/Asp.NetCore2/SqlSugar/Utilities/UtilConstants.cs

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

Loading…
Cancel
Save