DataSource.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Vit.Linq.MsTest
  5. {
  6. public class DataSource
  7. {
  8. #region (x.1) BuildDataSource
  9. public static List<ModelA> BuildDataSource()
  10. {
  11. var list = new List<ModelA>(1000);
  12. for (int i = 0; i < 1000; i++)
  13. {
  14. list.Add(new ModelA
  15. {
  16. id = i,
  17. pid = i / 10,
  18. name = "name" + i,
  19. addTime = DateTime.Now,
  20. ext = "ext" + i
  21. }.BuildB());
  22. }
  23. return list;
  24. }
  25. public static IQueryable GetIQueryable() => BuildDataSource().AsQueryable();
  26. public static IQueryable<ModelA> GetQueryable() => BuildDataSource().AsQueryable();
  27. public class ModelA
  28. {
  29. public int id;
  30. public int? pid;
  31. public string name { get; set; }
  32. public DateTime addTime;
  33. public string ext;
  34. public ModelB b1;
  35. public ModelB[] ba;
  36. public ModelA BuildB()
  37. {
  38. b1 = new ModelB { name = name + "_b1", pid = pid };
  39. ba = new[] { b1 };
  40. return this;
  41. }
  42. public class ModelB
  43. {
  44. public int? pid;
  45. public string name;
  46. }
  47. }
  48. #endregion
  49. }
  50. }