I have the following code:
public class BaseEmployee
{
public bool Status {get;set;}
public DateTime DateOfJoining {get;set;}
}
public class Employee : BaseEmployee
{
public string Name {get;set;}
public string City {get;set;}
public string State {get;set;}
}
foreach(var record in records)
{
var employee = GetDefaultBaseEmployeeProperties();
employee.Name = record.Name
employee.State = record.Name;
employee.City = record.city;
Department.Employess.Add(employee)
}
When I do this then all the employees get updated with the same of name, city and state as the last employee added. So to get around the problem of reference I did
Department.Employees.Add(new Employee {
Name = record.Name;
City = record.City;
State = record.State;
});
But the problem with this approach is that I loose the BaseEmployee properties in the employee object.
I need a way of adding the employee to the Department.Employees with the base properties retained. any ideas from you people, without touching the base class.
FYI: moving the base class properties to the employee class is not an option.
GetDefaultBaseEmployeeProperties().BaseEmployeeproperties.Why would you think that ?