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.

71 lines
2.1 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 DbFirst : DemoBase
  9. {
  10. public static void Init()
  11. {
  12. var db = GetInstance();
  13. //Create all class
  14. db.DbFirst.CreateClassFile("c:\\Demo\\1");
  15. //Create student calsss
  16. db.DbFirst.Where("Student").CreateClassFile("c:\\Demo\\2");
  17. //Where(array)
  18. //Mapping name
  19. db.MappingTables.Add("ClassStudent", "Student");
  20. db.MappingColumns.Add("NewId", "Id", "ClassStudent");
  21. db.DbFirst.Where("Student").CreateClassFile("c:\\Demo\\3");
  22. //Remove mapping
  23. db.MappingTables.Clear();
  24. //Create class with default value
  25. db.DbFirst.IsCreateDefaultValue().CreateClassFile("c:\\Demo\\4", "Demo.Models");
  26. //Mapping and Attribute
  27. db.MappingTables.Add("ClassStudent", "Student");
  28. db.MappingColumns.Add("NewId", "Id", "ClassStudent");
  29. db.DbFirst.IsCreateAttribute().Where("Student").CreateClassFile("c:\\Demo\\5");
  30. //Remove mapping
  31. db.MappingTables.Clear();
  32. db.MappingColumns.Clear();
  33. //Custom format,Change old to new
  34. db.DbFirst.
  35. SettingClassTemplate(old =>
  36. {
  37. return old;
  38. })
  39. .SettingNamespaceTemplate(old =>
  40. {
  41. return old;
  42. })
  43. .SettingPropertyDescriptionTemplate(old =>
  44. {
  45. return @" /// <summary>
  46. /// Desc_New:{PropertyDescription}
  47. /// Default_New:{DefaultValue}
  48. /// Nullable_New:{IsNullable}
  49. /// </summary>";
  50. })
  51. .SettingPropertyTemplate(old =>
  52. {
  53. return old;
  54. })
  55. .SettingConstructorTemplate(old =>
  56. {
  57. return old;
  58. })
  59. .CreateClassFile("c:\\Demo\\6");
  60. }
  61. }
  62. }