diff --git a/Src/Asp.NetCore2/SqliteTest/UnitTest/CrossDatabase02.cs b/Src/Asp.NetCore2/SqliteTest/UnitTest/CrossDatabase02.cs index 9a7d57078..f3b4d1b04 100644 --- a/Src/Asp.NetCore2/SqliteTest/UnitTest/CrossDatabase02.cs +++ b/Src/Asp.NetCore2/SqliteTest/UnitTest/CrossDatabase02.cs @@ -1,14 +1,118 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text; - +using SqlSugar; namespace OrmTest { public class CrossDatabase02 { - public static void Init() + public static void Init() { + var db = new SqlSugarClient(new List() + { + new ConnectionConfig(){ConfigId="A",DbType=DbType.Sqlite,ConnectionString="DataSource=/A_DB.sqlite",IsAutoCloseConnection=true}, + new ConnectionConfig(){ConfigId="B",DbType=DbType.Sqlite,ConnectionString="DataSource=/B_DB.sqlite",IsAutoCloseConnection=true }, + new ConnectionConfig(){ConfigId="AB",DbType=DbType.Sqlite,ConnectionString="DataSource=/AB_DB.sqlite",IsAutoCloseConnection=true } + }); + + db.GetConnection("A").CodeFirst.InitTables(); + db.GetConnection("B").CodeFirst.InitTables(); + db.GetConnection("AB").CodeFirst.InitTables(); + + db.GetConnection("A").DbMaintenance.TruncateTable(); + db.GetConnection("B").DbMaintenance.TruncateTable(); + db.GetConnection("AB").DbMaintenance.TruncateTable(); + + db.GetConnection("A").Insertable(new OperatorInfo() { id=10, realname="A"}).ExecuteCommand(); + db.GetConnection("B").Insertable(new Role() { id=101, name="B"}).ExecuteCommand(); + db.GetConnection("AB").Insertable(new OptRole() { id=1, operId=10, roleId=101}).ExecuteCommand(); + + var x=db.Queryable() + .CrossQueryWithAttr().Includes(z => z.Roles).ToList(); + + if (x.First().Roles.Count == 0) + { + throw new Exception("unit error"); + } + } + /// + /// 描述: + /// 作者:synjones + /// 时间:2022-04-20 21:30:28 + /// + [SugarTable("unit_operatorinfo")] + [Tenant("A")] + public partial class OperatorInfo + { + /// + /// 主键 + /// + [SugarColumn(IsPrimaryKey = true)] + public int id { get; set; } + + /// + /// 姓名 + /// + public string realname { get; set; } + + /// + /// 多角色 + /// + [Navigate(typeof(OptRole), nameof(OptRole.operId), nameof(OptRole.roleId))]//名字换 + public List Roles { get; set; } + } + + /// + /// 描述: + /// 作者:synjones + /// 时间:2022-04-20 21:30:28 + /// + [SugarTable("unit_role1")] + [Tenant("B")] + public partial class Role + { + /// + /// 角色 + /// + [SugarColumn(IsPrimaryKey = true )] + public int id { get; set; } + + /// + /// 角色名称 + /// + public string name { get; set; } + + } + + + /// + /// 描述: + /// 作者:synjones + /// 时间:2022-04-21 14:35:09 + /// + [SugarTable("unit_operator_role")] + [Tenant("AB")] + public partial class OptRole + { + /// + /// + /// + [SugarColumn(IsPrimaryKey = true)] + public int id { get; set; } + + /// + /// + /// + public int operId { get; set; } + + /// + /// + /// + public int roleId { get; set; } + + } } } diff --git a/Src/Asp.NetCore2/SqliteTest/UnitTest/Main.cs b/Src/Asp.NetCore2/SqliteTest/UnitTest/Main.cs index ed745d655..aec237774 100644 --- a/Src/Asp.NetCore2/SqliteTest/UnitTest/Main.cs +++ b/Src/Asp.NetCore2/SqliteTest/UnitTest/Main.cs @@ -31,6 +31,7 @@ namespace OrmTest } public static void Init() { + CrossDatabase02.Init(); CrossDatabase03.Init(); ULock.Init(); UNavQuery01.Init();