Demo3_Insertable.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using SqlSugar;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using Uninpho.DBOperation.Model;
  6. namespace Uninpho.DBOperation.Operation
  7. {
  8. public class Demo3_Insertable
  9. {
  10. public static void Test()
  11. {
  12. SqlSugarClient db = Config.GetPgClient();
  13. var insertObj = new User() { Id = 1, Name = "order1",Price=0 };
  14. var updateObjs = new List<User> {
  15. new User() { Id = 11, Name = "order11", Price=0 },
  16. new User() { Id = 12, Name = "order12" , Price=0}
  17. };
  18. //Only insert Name and Price
  19. db.Insertable(insertObj).InsertColumns(it => new { it.Name, it.Price }).ExecuteReturnIdentity();
  20. db.Insertable(insertObj).InsertColumns("Name", "Price").ExecuteReturnIdentity();
  21. //ignore null columns
  22. db.Insertable(updateObjs).ExecuteCommand();//get change row count
  23. //Use Lock
  24. db.Insertable(insertObj).With(SqlWith.UpdLock).ExecuteCommand();
  25. Console.WriteLine("#### Insertable End ####");
  26. }
  27. }
  28. }