From 2ea3064986ade93fdb926b1b9586c3064665f6d1 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Tue, 19 Mar 2024 22:31:24 +0800 Subject: [PATCH] Add user test case --- .../UserTestCases/UnitTest/Main.cs | 1 + .../UnitTest/UnitDynamicCoread12321.cs | 101 ++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/UnitDynamicCoread12321.cs diff --git a/Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/Main.cs b/Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/Main.cs index a984e58f8..57b8960a3 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/Main.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/Main.cs @@ -33,6 +33,7 @@ namespace OrmTest } public static void Init() { + UnitDynamicCoread12321.Init(); UnitManyToManyadfafa.Init(); UnitAsyncToken.Init(); UnitManyToMany121231.Init(); diff --git a/Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/UnitDynamicCoread12321.cs b/Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/UnitDynamicCoread12321.cs new file mode 100644 index 000000000..9a7523378 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/UnitDynamicCoread12321.cs @@ -0,0 +1,101 @@ +using SqlSugar; +using System; +using System.Linq.Dynamic.Core; +using System.Threading.Tasks; + +namespace OrmTest +{ + public class UnitDynamicCoread12321 + { + /// + /// 管理系统角色 + /// + [SugarTable("a", IsDisabledUpdateAll = true)] + public class AT + { + + /// + /// 角色名称 + /// + [SugarColumn(ColumnName = "id")] + public long Id { get; set; } + + /// + /// 角色名称 + /// + [SugarColumn(ColumnName = "name", Length = 100)] + public string Name { get; set; } = string.Empty; + + /// + /// 角色描述 + /// + [SugarColumn(ColumnName = "desc", Length = 100)] + public string Desc { get; set; } = string.Empty; + + public string BName { get; set; } + + } + + /// + /// 管理系统角色 + /// + [SugarTable("b", IsDisabledUpdateAll = true)] + public class BT + { + + /// + /// 角色名称 + /// + [SugarColumn(ColumnName = "id")] + public long Id { get; set; } + + + /// + /// 角色名称 + /// + [SugarColumn(ColumnName = "aid")] + public long Aid { get; set; } + + /// + /// 角色名称 + /// + [SugarColumn(ColumnName = "name", Length = 100)] + public string Name { get; set; } = string.Empty; + + /// + /// 角色描述 + /// + [SugarColumn(ColumnName = "desc", Length = 100)] + public string Desc { get; set; } = string.Empty; + + } + + + public static void Init() + { + + StaticConfig.DynamicExpressionParserType = typeof(DynamicExpressionParser); + var db = NewUnitTest.Db; + + var shortNames = DynamicParameters.Create("x", typeof(AT), "u", typeof(BT)); + var sql = db.QueryableByObject(typeof(AT), "x") + .AddJoinInfo(typeof(BT), + shortNames, + $"x.Id==u.Aid", + JoinType.Left) + .Select(shortNames, $"new (x.Name as Name,u.Name as BName)", typeof(AT)) + .ToSql().Key; + if (sql.Contains( "Aid")) + { + throw new Exception("unit error"); + } + + Console.WriteLine(sql); + + /// SELECT `x`.`name` AS `Name` , `u`.`name` AS `BName` FROM `a` x Left JOIN `b` `u` ON ( `x`.`id` = `u`.`Aid` ) + + + } + } + +}