I searched and searched, and cannot find a solution to something that seems should be easy to do. Here is an example of my classes.
public class Employee
{
// Some properties
}
public class Employees : List<Employee>
{
}
I use the Employees class to simplify variable declarations, but may also place some other code there, like getting aggregate information, etc.
The problem occurs when I use linq functions on it, usually Where. For example:
Employees employees = csv.LoadEmployees(txtEmployeeMasterFileName.Text);
employees = employees.Where(emp => emp.Status.ToUpper() == "A"); // Only select active employees
I get a compile time error:
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<Payroll_Migration.Model.Employee>' to 'Payroll_Migration.Model.Employees'. An explicit conversion exists (are you missing a cast?)
If I add an explicit cast like this:
employees = (Employees)employees.Where(emp => emp.Status.ToUpper() == "A");
I get a runtime error:
Unable to cast object of type 'WhereListIterator`1[Payroll_Migration.Model.Employee]' to type 'Payroll_Migration.Model.Employees'.
Is there any way around this, or do I have to use List instead of Employees?