using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace OrmTest { public partial class NewUnitTest { public static void Json() { Db.CodeFirst.InitTables(); Db.CodeFirst.InitTables(); Db.DbMaintenance.TruncateTable(); Db.Insertable(new UnitJsonTest() { Order = new Order { Id = 1, Name = "order1" } }).ExecuteCommand(); var list = Db.Queryable().ToList(); UValidate.Check("order1", list.First().Order.Name, "Json"); Db.Updateable(new UnitJsonTest() { Id = 1, Order = new Order { Id = 2, Name = "order2" } }).ExecuteCommand(); list= Db.Queryable().ToList(); UValidate.Check("order2", list.First().Order.Name, "Json"); var list2 = Db.Queryable().ToList(); var x = new Order() { Name="a" }; Db.Updateable() .SetColumns(it => it.Name=="a") .Where(it=>it.Id==1) .ExecuteCommand(); var list3=Db.Queryable().Select(it => new { x = it }).ToList(); if (list3[0].x == null) { 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().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() .LeftJoin((a, b) => a.Pid == b.Id) .Select((a, b) => new { a, b }).ToList(); #endregion db.CodeFirst.SetStringDefaultLength(2000).InitTables(); db.Insertable(new UnitJsonTestadsga1() { os = new List()}).ExecuteCommand(); db.Insertable(new UnitJsonTestadsga1() { os = new List() { new Order() { CreateTime=DateTime.Now} } }).ExecuteCommand(); var list10= db.Queryable().Select(it => new { it }).ToList(); } } public class UnitJsonTestadsga1 { [SqlSugar.SugarColumn(Length =2000,IsJson =true)] public List os{get;set;} } public class UnitJsonTest2 { [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] 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 { [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] public int Id { get; set; } [SqlSugar.SugarColumn(ColumnDataType = "varchar(max)", IsJson = true)] public Order Order { get; set; } } }