Instantiate defined object with Linq Query
Posted
by
Heinz
on Stack Overflow
See other posts from Stack Overflow
or by Heinz
Published on 2011-01-28T23:15:04Z
Indexed on
2011/01/28
23:26 UTC
Read the original article
Hit count: 251
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();
© Stack Overflow or respective owner