Queryable.Select json array bug

This commit is contained in:
sunkaixuna 2022-01-07 13:28:38 +08:00
parent 8aa4ed37fc
commit 1f7d4121a3
4 changed files with 56 additions and 3 deletions

View File

@ -94,6 +94,7 @@
<Compile Include="Models\OrderItem.cs" />
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
<Compile Include="Models\ViewOrder.cs" />
<Compile Include="UnitTest\Models\TestModel.cs" />
<Compile Include="UnitTest\UCustom01.cs" />
<Compile Include="UnitTest\UCustom02.cs" />
<Compile Include="UnitTest\UCustom03.cs" />

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SqlSugarSelect
{
[SqlSugar.SugarTable("UnitTestModel1")]
public class TestModel1
{
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public string Titlt { get; set; }
[SqlSugar.SugarColumn(ColumnDataType = "ntext", IsJson = true)]
public Guid[] Ids { get; set; }
}
[SqlSugar.SugarTable("UnitTestModel2")]
public class TestModel2
{
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public int Pid { get; set; }
}
}

View File

@ -34,6 +34,30 @@ namespace OrmTest
{
throw new Exception("unit error");
}
var db = Db;
db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(SqlSugarSelect.TestModel1));
db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(SqlSugarSelect.TestModel2));
#region
var isadd = !db.Queryable<TestModel1>().Any();
if (isadd)
{
db.Insertable(new SqlSugarSelect.TestModel1
{
Ids = new Guid []{ Guid.NewGuid() },
Titlt = "123"
}).ExecuteCommand();
db.Insertable(new SqlSugarSelect.TestModel2
{
Pid = 1
}).ExecuteCommand();
}
#endregion
#region Bug所在处
var rv = db.Queryable<SqlSugarSelect.TestModel2>()
.LeftJoin<SqlSugarSelect.TestModel1>((a, b) => a.Pid == b.Id)
.Select((a, b) => new { a, b }).ToList();
#endregion
}
}

View File

@ -408,14 +408,18 @@ namespace SqlSugar
var jsonString = readerValues.First(it => it.Key.EqualCase(key)).Value;
if (jsonString != null)
{
if (jsonString.ToString().First() == '{'&& jsonString.ToString().Last() == '}')
if (jsonString.ToString().First() == '{' && jsonString.ToString().Last() == '}')
{
result.Add(name, this.DeserializeObject<Dictionary<string, object>>(jsonString + ""));
}
else if (jsonString.ToString().Replace(" ","")!="[]"&&!jsonString.ToString().Contains("{")&&!jsonString.ToString().Contains("}"))
{
result.Add(name, this.DeserializeObject<dynamic>(jsonString + ""));
}
else
else
{
result.Add(name, this.DeserializeObject<List<Dictionary<string, object>>>(jsonString + ""));
}
}
}