Browse Source

SetColumns Json bug

pull/9/head
sunkaixuna 3 years ago
parent
commit
9d79237a61
  1. 7
      Src/Asp.Net/SqlServerTest/UnitTest/UJson.cs
  2. 8
      Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs
  3. 12
      Src/Asp.Net/SqlSugar/Utilities/UtilConvert.cs

7
Src/Asp.Net/SqlServerTest/UnitTest/UJson.cs

@ -21,6 +21,11 @@ namespace OrmTest
list= Db.Queryable<UnitJsonTest>().ToList();
UValidate.Check("order2", list.First().Order.Name, "Json");
var list2 = Db.Queryable<UnitJsonTest>().ToList();
var x = new Order() { Name="a" };
Db.Updateable<UnitJsonTest2>()
.SetColumns(it => it.Name=="a")
.Where(it=>it.Id==1)
.ExecuteCommand();
}
}
@ -30,6 +35,8 @@ namespace OrmTest
public int Id { get; set; }
[SqlSugar.SugarColumn(IsJson = true)]
public Order Order { get; set; }
[SqlSugar.SugarColumn(IsNullable =true)]
public string Name { get; set; }
}
public class UnitJsonTest
{

8
Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs

@ -316,7 +316,7 @@ namespace SqlSugar
public IUpdateable<T> SetColumns(Expression<Func<T, bool>> columns)
{
ThrowUpdateByObject();
CheckTranscodeing();
var binaryExp = columns.Body as BinaryExpression;
Check.Exception(!binaryExp.NodeType.IsIn(ExpressionType.Equal), "No support {0}", columns.ToString());
Check.Exception(!(binaryExp.Left is MemberExpression) && !(binaryExp.Left is UnaryExpression), "No support {0}", columns.ToString());
@ -327,6 +327,12 @@ namespace SqlSugar
expResult = Regex.Split(expResult, " IS NULL ")[0]+" = NULL ";
}
string key = SqlBuilder.GetNoTranslationColumnName(expResult);
if (EntityInfo.Columns.Where(it=>it.IsJson||it.IsTranscoding).Any(it => it.DbColumnName.EqualCase(key) || it.PropertyName.EqualCase(key)))
{
CheckTranscodeing();
}
UpdateBuilder.SetValues.Add(new KeyValuePair<string, string>(SqlBuilder.GetTranslationColumnName(key), expResult));
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => (UpdateParameterIsNull == false && IsPrimaryKey(it)) || UpdateBuilder.SetValues.Any(v => SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase) || SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey == true).ToList();
AppendSets();

12
Src/Asp.Net/SqlSugar/Utilities/UtilConvert.cs

@ -55,7 +55,17 @@ namespace SqlSugar
}
return errorValue;
}
public static bool EqualCase(this string thisValue,string equalValue)
{
if ( thisValue!=null && equalValue != null)
{
return thisValue.ToLower() == equalValue.ToLower();
}
else
{
return thisValue == equalValue;
}
}
public static string ObjToString(this object thisValue)
{
if (thisValue != null) return thisValue.ToString().Trim();

Loading…
Cancel
Save