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();
That should work absolutely fine. Do your properties definitely work? I suggest you put breakpoints on them and see whether they get called, and what the values are at that point.
EDIT: Okay, this sounds like it could be a Subsonic issue. I suggest you force the last part to be done in-process using
AsEnumerable: