DataSource.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Vit.Linq.MsTest
  5. {
  6. public class Person
  7. {
  8. public int id;
  9. public int? departmentId;
  10. public string name { get; set; }
  11. public DateTime addTime;
  12. public string ext;
  13. public bool isEven;
  14. public Job job;
  15. public Job[] jobArray;
  16. public List<Job> jobList;
  17. public Person PopulateJob()
  18. {
  19. job = new Job { departmentId = departmentId, personId = id, name = name + "_job1" };
  20. var job2 = new Job { departmentId = departmentId, personId = id, name = name + "_job2" };
  21. if (id % 2 == 0)
  22. jobArray = new[] { job, job2 };
  23. else
  24. jobArray = new[] { job };
  25. jobList = jobArray.ToList();
  26. return this;
  27. }
  28. public int GetJobCount()
  29. {
  30. return jobList.Count;
  31. }
  32. public bool JobExistAtIndex(int index)
  33. {
  34. if (index < jobList.Count) return true;
  35. return false;
  36. }
  37. public Job GetJobAtIndex(int index)
  38. {
  39. if (index < jobList.Count) return jobList[index];
  40. return null;
  41. }
  42. }
  43. public class Job
  44. {
  45. public int? departmentId;
  46. public int? personId;
  47. public string name;
  48. public string GetJobName()
  49. {
  50. return name;
  51. }
  52. }
  53. public partial class DataSource
  54. {
  55. public static List<Person> BuildDataSource(int count = 1000)
  56. {
  57. var Now = DateTime.Now;
  58. var list = new List<Person>(count);
  59. for (int i = 0; i < count; i++)
  60. {
  61. list.Add(new Person
  62. {
  63. id = i,
  64. departmentId = i / 10,
  65. name = "name" + i,
  66. addTime = Now.AddSeconds(i),
  67. ext = "ext" + i,
  68. isEven = i % 2 == 0
  69. }.PopulateJob());
  70. }
  71. return list;
  72. }
  73. public static IQueryable GetIQueryable() => GetQueryable();
  74. public static IQueryable<Person> GetQueryable() => BuildDataSource().AsQueryable();
  75. }
  76. }