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.

55 lines
1.8 KiB

2 years ago
  1. using SqlSugar;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace OrmTest.Demo
  7. {
  8. public class CodeTable
  9. {
  10. [SugarColumn(IsNullable =false ,IsPrimaryKey =true,IsIdentity =true)]
  11. public int Id { get; set; }
  12. [SugarColumn(Length = 21,OldColumnName = "Name2")]
  13. public string Name{ get; set; }
  14. [SugarColumn(IsNullable = true,Length =10)]
  15. public string IsOk { get; set; }
  16. public Guid Guid { get; set; }
  17. [SugarColumn(ColumnDataType ="int")]
  18. public decimal Decimal { get; set; }
  19. [SugarColumn(IsNullable = true)]
  20. public DateTime? DateTime { get; set; }
  21. [SugarColumn(IsNullable = true,OldColumnName = "Dob")]
  22. public double? Dob2 { get; set; }
  23. [SugarColumn(Length =11000)]
  24. public string A1 { get; set; }
  25. [SugarColumn(Length = 18,DecimalDigits=2)]
  26. public decimal Dec { get; set; }
  27. }
  28. public class CodeTable2 {
  29. public int Id { get; set; }
  30. public string Name { get; set; }
  31. [SugarColumn(IsIgnore =true)]
  32. public string TestId { get; set; }
  33. }
  34. public class CodeFirst : DemoBase
  35. {
  36. public static void Init()
  37. {
  38. SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
  39. {
  40. ConnectionString = Config.ConnectionString,
  41. DbType = DbType.SqlServer,
  42. IsAutoCloseConnection = true,
  43. InitKeyType = InitKeyType.Attribute
  44. });
  45. //Backup table
  46. //db.CodeFirst.BackupTable().InitTables(typeof(CodeTable),typeof(CodeTable2));
  47. //No backup table
  48. db.CodeFirst.InitTables(typeof(CodeTable),typeof(CodeTable2));
  49. }
  50. }
  51. }