You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.2 KiB

2 years ago
  1. using OrmTest.Models;
  2. using SqlSugar;
  3. namespace OrmTest.Demo
  4. {
  5. public class QueryableView : DemoBase
  6. {
  7. public static void Init()
  8. {
  9. var db = GetInstance();
  10. var q1 = db.Queryable<Student, School>((st, sc) => new object[] {
  11. JoinType.Left,st.SchoolId==sc.Id
  12. }).Select((st, sc) => new ViewModelStudent4() { Id = st.Id, Name = st.Name, SchoolName = sc.Name });
  13. var q2 = db.Queryable<School>();
  14. var innerJoinList = db.Queryable(q1, q2, (j1, j2) => j1.Id == j2.Id).Select((j1, j2) => j1).ToList();//inner join
  15. var innerJoinList2 = db.Queryable(q1, q2, (j1, j2) => j1.Id == j2.Id).Select((j1, j2) => j1).ToSql();//inner join
  16. var leftJoinList = db.Queryable(q1, q2, JoinType.Left, (j1, j2) => j1.Id == j2.Id).Select((j1, j2) => j1).ToList();//left join
  17. var leftJoinList1 = db.Queryable(q1, q2, JoinType.Left, (j1, j2) => j1.Id == j2.Id).Select((j1, j2) => j1).ToSql();//left join
  18. }
  19. }
  20. public class ViewModelStudent4
  21. {
  22. public int Id { get; set; }
  23. public string SchoolName { get; set; }
  24. public string Name { get; set; }
  25. }
  26. }