二级导航查询加条件 返回
SqlSugar
老数据
1
1055
悬赏:0 飞吻
public class StudentA{ [SugarColumn(IsPrimaryKey = true)] public int StudentId { get; set; } public string Name { get; set; } public int SchoolId { get; set; } [Navigate(NavigateType.OneToOne, nameof(SchoolId))]//一对一 public SchoolA SchoolA { get; set; } [Navigate(NavigateType.OneToMany, nameof(BookA.studenId))]//一对多 public List<BookA> Books { get; set; }//只能是null不能赋默认值}public class SchoolA{ [SugarColumn(IsPrimaryKey = true)] public int SchoolId { get; set; } public string SchoolName { get; set; } [Navigate(NavigateType.OneToMany, nameof(RoomA.SchoolId))]//一对多 public List<RoomA> RoomList { get; set; }//只能是null不能赋默认值}public class RoomA{ [SugarColumn(IsPrimaryKey = true)] public int RoomId { get; set; } public string RoomName { get; set; } public int SchoolId { get; set; }}public class BookA{ [SugarColumn(IsPrimaryKey = true)] public int BookId { get; set; } public string Name { get; set; } public int studenId { get; set; }} var list2 = db.Queryable<StudentA>() //查2层 .Includes(st => st.SchoolA, sch=> sch.RoomList)//查询2级(等于EF ThenInclude) //查1层 .Includes(st=> st.Books) .ToList()这个是文档中多级导航的例子,那假如我想获取所有RoomName为"Room1"的学生呢?该怎么写
热忱回答(1)
-
朽木 VIP0
2023/2/6已经解决。发现我实际的问题和这个不太一样,就不贴处理方法了。
0 回复