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.

36 lines
1.1 KiB

2 years ago
  1. using OrmTest.Models;
  2. using SqlSugar;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace OrmTest.Demo
  9. {
  10. public class Delete:DemoBase
  11. {
  12. public static void Init()
  13. {
  14. var db = GetInstance();
  15. //by entity
  16. var t1 = db.Deleteable<Student>().Where(new Student() { Id = 1 }).ExecuteCommand();
  17. //use lock
  18. var t2 = db.Deleteable<Student>().With(SqlWith.RowLock).ExecuteCommand();
  19. //by primary key
  20. var t3 = db.Deleteable<Student>().In(1).ExecuteCommand();
  21. //by primary key array
  22. var t4 = db.Deleteable<Student>().In(new int[] { 1, 2 }).ExecuteCommand();
  23. //by expression id>1 and id==1
  24. var t5 = db.Deleteable<Student>().Where(it => it.Id > 1).Where(it => it.Id == 1).ExecuteCommand();
  25. var t6 = db.Deleteable<Student>().AS("student").Where(it => it.Id > 1).Where(it => it.Id == 1).ExecuteCommandAsync();
  26. t6.Wait();
  27. }
  28. }
  29. }