.NET 6 跨服务器联表查询( 二 )

3.2 跨库查询之一对多 [Tenant("db1")]//指定是db1  (OrderItem类设置为 db2)  public class Order  {            [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]            public int Id { get; set; }            public string Name { get; set; }            public decimal Price { get; set; }            [SugarColumn(IsNullable = true)]            public DateTime CreateTime { get; set; }            [SugarColumn(IsNullable = true)]            public int CustomId { get; set; }            [Navigate(NavigateType.OneToMany, nameof(OrderItem.OrderId))]//            public List<OrderItem> Items { get; set; }  }  var list = db.QueryableWithAttr<Order>()                    .Includes(z => z.Items)//跨库一对多                    .ToList();3.3 跨库查询之多对多我们将3个表扔进3个不同的库里面
【.NET 6 跨服务器联表查询】 var db = new SqlSugarClient(new List<ConnectionConfig>()    {        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  }  });p  实体
       [Tenant("A")]//指定为A库        public partial class OperatorInfo        {            /// <summary>            /// 主键            /// </summary>            [SugarColumn(IsPrimaryKey = true)]            public int id { get; set; }            /// <summary>            /// 姓名            /// </summary>            public string realname { get; set; }            /// <summary>            /// 多角色            /// </summary>            [Navigate(typeof(OptRole), nameof(OptRole.operId), nameof(OptRole.roleId))]//配置导航            public List<Role> Roles { get; set; }        }        [Tenant("B")]//指定为B库        public partial class Role        {            /// <summary>            /// 角色            /// </summary>            [SugarColumn(IsPrimaryKey = true )]            public int id { get; set; }            /// <summary>            /// 角色名称            /// </summary>            public string name { get; set; }        }        [Tenant("AB")]//指定为AB库        public partial class OptRole        {            /// <summary>            ///            /// </summary>            [SugarColumn(IsPrimaryKey = true)]            public int id { get; set; }            /// <summary>            ///            /// </summary>            public int operId { get; set; }            /// <summary>            ///            /// </summary>            public int roleId { get; set; }        }//3个库3个表进行多对多查询var x=db.QueryableWithAttr<OperatorInfo>().Includes(z => z.Roles).ToList();

经验总结扩展阅读