Instantiate defined object with Linq Query
- by Heinz
I know that you can instantiate anonymous types with Linq but I am looking to instantiate an object I have already defined. Every time I do, all the properties are returned with their defaults (null, 0, etc.) Is there a way to make this work?
I've tried something like this:
ServiceDepartment[] serviceDepartments = (from d in departments
orderby d.department_name
select new ServiceDepartment
{
DepartmentID = d.department_id,
DepartmentName = d.department_name
}).ToArray();