Hi,
How to identify duplicate row based upon fields.
I have Initially some data.
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
public List<Customer> Customers;
}
public class Customer
{
public int ID { get; set; }
public string Name { get; set; }
}
public List<Employee> GetOriginaldata()
{
List<Employee> employees = new List<Employee>()
{
new Employee(){Id=1,Name="a",Gender="male",Customers=CustomersData() },
new Employee(){Id=1,Name="a",Gender="male",Customers=CustomersData() },
new Employee() { Id = 1,Name = "a",Gender = "male",Customers = CustomersData() }
};
return employees;
}
later some data is coming from UI i need to check that data with original data and need to idenity duplicate row based upon below filds Name, Gender and Customers.
even one values not matches then consider that's not duplicate row.
public void GetDataFromUI()
{
List<Employee> originalData = GetOriginaldata();
//need to find duplicate row based upon data coming from UI based upon fileds (Name,Gender,Customers)
//scenario 1
//in this sceanrio i found duplicate row in GetOriginaldata
Employee employee = GetUIDataForScenarioOne();
//need to compare employee and original data and identity duplicate row and return true
Employee employee1 = GetUIDataForScenarioTwo();
//in this scenario return false since in customers i haven't found matching id's when comparing employee1 values with origianl data
//even though name and gender same also
}
public Employee GetUIDataForScenarioOne()
{
Employee employee = new Employee()
{
Name = "a",
Gender = "male",
Customers = new List<Customer>()
{
new Customer(){ID=3,Name="CustomerC"},
new Customer(){ID=4,Name="CustomerD"}
}
};
return employee;
}
public Employee GetUIDataForScenarioTwo()
{
Employee employee = new Employee()
{
Name = "a",
Gender = "male",
Customers = new List<Customer>()
{
new Customer(){ID=7,Name="CustomerC"},
new Customer(){ID=8,Name="CustomerD"}
}
};
return employee;
}