【发布时间】:2014-10-17 19:26:53
【问题描述】:
我正在尝试使用 EmployeeHistory 模型(对象 2)获取对 Employee 模型(对象 1)所做的更改的列表。基本上,只有一个员工记录,但有多个 EmployeeHistory 记录。每次对 Employee 进行更改时,都会将一条新记录添加到 EmployeeHistory 表中,其中包含更改之前的 Employee 数据。我想要一种方法来比较每个 EmployeeHistory Records 并返回一个报告所做更改的字符串列表。因此,为了获取更改列表,我想遍历 EmployeeHistory 记录列表并将每个 EmployeeHistory Record 与之前的 EmployeeHistory 记录进行比较。最后一条 EmployeeHistory 记录需要与当前的 Employee(对象 1)记录进行比较,后者的属性非常相似。有什么方法可以做到这一点,而不需要大量的 IF 语句来比较每条记录上的两个属性?
这就是我要找的东西:
public List<string> GetEmployeeMasterHistory(Models.EmployeeMaster employee,IEnumerable<EmployeeMasterHistory> employeeHistoryCollection)
{
foreach (var historyRecord in employeeHistoryCollection)
{
//Compare historyRecord to EmployeeCollection[historyRecord.Index() - 1]
}
return null;
}
我已经有一个方法可以对每个属性进行所有检查,但是将来会添加更多的属性,我厌倦了必须添加新的 IF 语句,而且看起来不太好高效。
这是 EmployeeMasterHistory Record 的样子:
public partial class EmployeeMasterHistory
{
public Nullable<int> EmployeeNumber { get; set; }
public Nullable<int> CompanyNumber { get; set; }
public string UserName { get; set; }
public string Initials { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName { get; set; }
public Nullable<bool> StatusFlag { get; set; }
public Nullable<System.DateTime> StartDate { get; set; }
public Nullable<System.DateTime> TerminationDate { get; set; }
public string Branch { get; set; }
public Nullable<int> DepartmentNumber { get; set; }
public string Supervisor { get; set; }
public Nullable<int> Shift { get; set; }
public Nullable<int> UnionNo { get; set; }
public string G2ID { get; set; }
public Nullable<bool> EnterTimeFl { get; set; }
public string Phone { get; set; }
public string Extension { get; set; }
public string CellPhone { get; set; }
public string Email { get; set; }
public Nullable<int> PrimaryJobRole { get; set; }
public Nullable<int> JobLevel { get; set; }
public Nullable<int> JobGroup { get; set; }
public string JobTitle { get; set; }
public string EmployeeType { get; set; }
public string PayType { get; set; }
public Nullable<decimal> Rate { get; set; }
public Nullable<System.DateTime> LastReviewDate { get; set; }
public Nullable<System.DateTime> NextReviewDate { get; set; }
public Nullable<System.DateTime> LastPayChangeDate { get; set; }
public string EmergencyContact { get; set; }
public string EmergencyContactRelationship { get; set; }
public string EmergencyContactPhone { get; set; }
public Nullable<bool> CPComputer { get; set; }
public Nullable<bool> CPPhone { get; set; }
public Nullable<bool> CPCreditCard { get; set; }
public Nullable<bool> CPGasCard { get; set; }
public Nullable<bool> CPKeys { get; set; }
public Nullable<bool> CPSecurityCard { get; set; }
public Nullable<bool> CPVehicle { get; set; }
public Nullable<bool> CPTools { get; set; }
public Nullable<bool> CPUniform { get; set; }
public string ModBy { get; set; }
public Nullable<System.DateTime> ModDate { get; set; }
public int ID { get; set; }
public string SalesRep { get; set; }
public string MiddleName { get; set; }
public Nullable<int> ManagerEmpNo { get; set; }
public Nullable<bool> TempFl { get; set; }
public Nullable<bool> PEWFl { get; set; }
public Nullable<bool> PGTFl { get; set; }
public Nullable<bool> PMPFl { get; set; }
public Nullable<bool> PPGEFl { get; set; }
public Nullable<bool> PPGFl { get; set; }
public Nullable<bool> PRCFl { get; set; }
public Nullable<bool> PTCFl { get; set; }
public Nullable<bool> PPFl { get; set; }
public Nullable<bool> SWPFl { get; set; }
public Nullable<int> PrimaryDivision { get; set; }
public string TechGroupID { get; set; }
public string TechLevelID { get; set; }
public Nullable<bool> TechATD { get; set; }
public Nullable<int> ReviewPeriod { get; set; }
public Nullable<bool> CorpFl { get; set; }
}
提前谢谢你!
【问题讨论】:
标签: c# reflection