多对多导航继承类存储及查询如何实现 返回

SqlSugar 沟通中
2 358


internal class _6_NavQuery
   {    
           private static void InitializeDatabase(SqlSugarClient db)
         {
         // Initialize and truncate tables for Student, School, and Book entities.
         // 初始化并清空Student、School和Book表。
         db.CodeFirst.InitTables<Student, School, Book>();
         db.DbMaintenance.TruncateTable<Student, School, Book>();
      
         db.CodeFirst.InitTables<A,B, ABMapping>();
         db.DbMaintenance.TruncateTable<A,  B, ABMapping>();
      
         List<A> a1 = new List<A> { new A() { Name = "A1" }, new A() { Name = "A2" } };
               var b1 = new B1 { Name = "B1" , Test = "sasd" };
               var b2 = new B2 { Name = "B2" , TestNum = 123};
               a1[0].BList = new List<B> { b1, b2 };
               db.InsertNav(a1).Include(x =>x.BList ).ExecuteCommand();
         
         var list4 = db.Queryable<A>().Includes(it => it.BList).ToList();
         }
  }
      
      
      
        [SugarTable("A06")]
        public class A
        {
            [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
            public int AId { get; set; }
            public string Name { get; set; }
            [Navigate(typeof(ABMapping), nameof(ABMapping.AId), nameof(ABMapping.BId))]
            public List<B> BList { get; set; }
        }
        [SugarTable("B06")]
        public class B
        {
            [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
            public int BId { get; set; }
            public string Name { get; set; }
            [Navigate(typeof(ABMapping), nameof(ABMapping.BId), nameof(ABMapping.AId))]
            public List<A> AList { get; set; }
        }
        [SugarTable("B01")]
        public class B1:B
        {
            public String Test {  get; set; }
        }
        [SugarTable("B02")]
        public class B2:B
        {
            public int TestNum { get; set; }
        }


类似这样的继承关系,能否使用导航查询出特定B1或B2并存入A类中的BList呢?


热忱回答2