DataSource.cs 1.5 KB

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