Update Select Json bug

This commit is contained in:
skx 2020-11-07 14:26:13 +08:00
parent d19b004229
commit 95bcefe1ac
5 changed files with 230 additions and 6 deletions

View File

@ -0,0 +1,46 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest.Test
{
public class BugTest4
{
public static void Init()
{
SqlSugarClient Db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = @"PORT=5433;DATABASE=x;HOST=localhost;PASSWORD=haosql;USER ID=postgres",
DbType = DbType.PostgreSQL,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute,
});
//调式代码 用来打印SQL
Db.Aop.OnLogExecuting = (sql, pars) =>
{
Console.WriteLine(sql);
};
Db.CodeFirst.InitTables(typeof(testmmxxxmm121));
Db.Insertable(new testmmxxxmm121() { name = (float) 0.01 , name2 = 1 }).ExecuteCommand();
var list= Db.Queryable<testmmxxxmm121>().ToList();
}
}
public class testmmxxxmm121
{
[SugarColumn(IsPrimaryKey =true,IsIdentity =true)]
public int id { get; set; }
[SugarColumn(ColumnDataType ="float4",IsNullable =true)]
public float? name { get; set; }
[SugarColumn(ColumnDataType = "float4", IsNullable = false)]
public float? name2 { get; set; }
}
}

View File

@ -0,0 +1,168 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
namespace OrmTest.Test
{
public class BugTest5
{
[SugarTable("User")]
public class User
{
[SugarColumn(IsNullable = false, ColumnDataType = "uuid", IsPrimaryKey = true)]
public Guid Id { get; set; }
/// <summary>
/// 部门名称
/// </summary>
[SugarColumn(IsNullable = false)]
public string Name { get; set; }
/// <summary>
/// 用户部门
/// </summary>
[SugarColumn(IsNullable = false, IsJson = true, ColumnDataType = "json")]
public List<Department> UserDpt { get; set; }
}
[SugarTable("User2")]
public class User2
{
[SugarColumn(IsNullable = false, ColumnDataType = "uuid", IsPrimaryKey = true)]
public Guid Id { get; set; }
[SugarColumn(IsNullable = false, ColumnDataType = "uuid")]
public Guid UserId { get; set; }
}
public class Department
{
public Guid Id { get; set; }
public string Name { get; set; }
}
public static void Init()
{
SqlSugarClient db = new SqlSugarClient(
new ConnectionConfig()
{
ConnectionString = Config.ConnectionString,
DbType = DbType.PostgreSQL,//设置数据库类型
IsAutoCloseConnection = true,//自动释放数据务,如果存在事务,在事务结束后释放
InitKeyType = InitKeyType.Attribute //从实体特性中读取主键自增列信息
});
db.Aop.OnError = (exp) =>//SQL报错
{
string sql = exp.Sql;
//exp.sql 这样可以拿到错误SQL
};
//db.DbMaintenance.CreateDatabase();
db.CodeFirst.InitTables(typeof(User), typeof(User2));
List<Department> departments = new List<Department>();
departments.Add(new Department { Id = Guid.NewGuid(), Name = "研发部" });
departments.Add(new Department { Id = Guid.NewGuid(), Name = "市场部" });
Guid userId = Guid.NewGuid();
User user = new User
{
Id = userId,
Name = "张三",
UserDpt = departments
};
db.Insertable(user).ExecuteCommand();
User2 user2 = new User2();
user2.Id = Guid.NewGuid();
user2.UserId = userId;
db.Insertable(user2).ExecuteCommand();
var data = db.Queryable<User, User2>((a, b) => new object[] { JoinType.Inner, a.Id == b.UserId })
.Where((a, b) => a.Id.ToString() == userId.ToString())
.Select((a, b) => new
{
User = a,
Items = a.UserDpt
}).ToList();
Console.ReadKey();
}
}
}

View File

@ -16,16 +16,16 @@ namespace OrmTest
/// Account have permission to create database
/// 用有建库权限的数据库账号
/// </summary>
public static string ConnectionString = "PORT=5432;DATABASE=SqlSugar4xTest;HOST=localhost;PASSWORD=haosql;USER ID=postgres";
public static string ConnectionString = "PORT=5433;DATABASE=SqlSugar4xTest;HOST=localhost;PASSWORD=haosql;USER ID=postgres";
/// <summary>
/// Account have permission to create database
/// 用有建库权限的数据库账号
/// </summary>
public static string ConnectionString2 = "PORT=5432;DATABASE=SqlSugar4xTest2;HOST=localhost;PASSWORD=haosql;USER ID=postgres";
public static string ConnectionString2 = "PORT=5433;DATABASE=SqlSugar4xTest2;HOST=localhost;PASSWORD=haosql;USER ID=postgres";
/// <summary>
/// Account have permission to create database
/// 用有建库权限的数据库账号
/// </summary>
public static string ConnectionString3 = "PORT=5432;DATABASE=SqlSugar4xTest3;HOST=localhost;PASSWORD=haosql;USER ID=postgres";
public static string ConnectionString3 = "PORT=5433;DATABASE=SqlSugar4xTest3;HOST=localhost;PASSWORD=haosql;USER ID=postgres";
}
}

View File

@ -61,8 +61,10 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Bugs\BugTest.cs" />
<Compile Include="Bugs\BugTest4.cs" />
<Compile Include="Bugs\BugTest3.cs" />
<Compile Include="Bugs\BugTest2.cs" />
<Compile Include="Bugs\BugTest5.cs" />
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
<Compile Include="Demo\Demo1_Queryable.cs" />
<Compile Include="Demo\Demo2_Updateable.cs" />

View File

@ -281,11 +281,19 @@ namespace SqlSugar
if (readerValues != null &&
readerValues.Count == 1 &&
readerValues.First().Key == name &&
readerValues.First().Value!=null&&
readerValues.First().Value.GetType()==UtilConstants.StringType&&
readerValues.First().Value != null &&
readerValues.First().Value.GetType() == UtilConstants.StringType &&
Regex.IsMatch(readerValues.First().Value.ObjToString(), @"^\{.+\}$"))
{
result.Add(name, DeserializeObject<Dictionary<string,object>>(readerValues.First().Value.ObjToString()));
result.Add(name, DeserializeObject<Dictionary<string, object>>(readerValues.First().Value.ObjToString()));
}
else if (item.PropertyType.FullName.IsCollectionsList()&&
readerValues.ContainsKey(item.Name.ToLower())&&
readerValues[item.Name.ToLower()]!=null&&
readerValues[item.Name.ToLower()].GetType()==UtilConstants.StringType&&
Regex.IsMatch(readerValues[item.Name.ToLower()].ToString(), @"^\[{.+\}]$"))
{
result.Add(name, DeserializeObject<List<Dictionary<string, object>>>(readerValues[item.Name.ToLower()].ToString()));
}
else
{