LINQ - Error Converting Generic Type List<Employee> to another List<EmpAddress>

Asked By Nikhal Sood on 05-Mar-13 04:25 PM

I have a Employee and EmployeeAddress class.

Public Class Employee{

Public Employee{

address = new List<EmployeeAdress>();

}

List<EmployeeAdress> address { get; set; }

}

Public Class EmployeeAddress{

public string address;

public string zip;

public string state;

}

<div></div> <div>I have Employee class populated with data having EmployeeAddress as a list.</div> <div></div> <div>I am trying to find out the list of employee in specific zipCode.</div> <div></div> <div>

foreach (string zipCode in ZipCodes)
{ 
foreach (Emplopyee emp in listEmployee)
{

List<Employee> empList = Emplopyee.EmplopyeeAddress.Where(x => x.zip == zipCode));

}
}

I am gettting an error converting EmployeeAddress to Employee. Tried couple of different ways but not able to resolve the error. Any help would be appreciated.

</div>
Robbe Morris replied to Nikhal Sood on 05-Mar-13 05:11 PM
Why would you think that a list containing EmployeeAddress class objects could be converted to a completely different class object type of Employee?

The EmployeeAddress class has no knowledge of what an Employee is.