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.

43 lines
1.5 KiB

2 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using SqlSugar;
  6. namespace OrmTest.Demo
  7. {
  8. public class AttributeDemo : DemoBase
  9. {
  10. public static void Init()
  11. {
  12. var db = GetInstance();
  13. AttributeTest a = new AttributeTest()
  14. {
  15. Name = "attr"
  16. };
  17. db.Insertable(a).AS("student").ExecuteCommand();
  18. var list = db.Queryable<AttributeTest>().AS("student").ToList();
  19. var list2 = db.Queryable<AttributeTest>().AS("student").Select(it => new AttributeTest() { Aid = it.Aid + 1,CreateTime=DateTime.Now,Name=it.Name }).ToList();
  20. var s = new AttributeTest2() { Aid = 1,AName="a", CreateTime=DateTime.Now };
  21. var count = db.Updateable(s).UpdateColumns(it=>new { it.CreateTime,it.AName }).Where(it=>it.Aid==100).ExecuteCommand();
  22. }
  23. public class AttributeTest
  24. {
  25. [SugarColumn(ColumnName = "Id")]
  26. public int Aid { get; set; }
  27. public string Name { get; set; }
  28. [SugarColumn(IsOnlyIgnoreInsert = true)]
  29. public DateTime CreateTime { get; set; }
  30. }
  31. [SugarTable("student")]
  32. public class AttributeTest2
  33. {
  34. [SugarColumn(ColumnName = "Id")]
  35. public int Aid { get; set; }
  36. [SugarColumn(ColumnName = "Name")]
  37. public string AName { get; set; }
  38. [SugarColumn(IsOnlyIgnoreInsert = true)]
  39. public DateTime CreateTime { get; set; }
  40. }
  41. }
  42. }