I'm currently using a lambda to set a property.
Team = department.Teams
.Where( t => t.GUID == a.Personnel.Roles
.Where(r=>r.Department==department && r.EndDate==null)
.SingleOrDefault()
.DeptTeamGUID)
.FirstOrDefault().Name
Department has a bunch of teams. A personnel has a role that is connected to that team. The PersonnelRole contains data about the department and which team the role is a part of.
However sometimes a personnel can have a role with no team. In this case I get a "Object reference not set to an instance of an object." exception.
I have also tried to modify the lambda to filter out Roles that doesn't have a DeptTeamGUID, but my logic seems off.
Team = department.Teams
.Where( t => t.GUID==a.Personnel.Roles
.Where( r => r.Department==department && r.EndDate==null
&& r.DeptTeamGUID !=null)
.SingleOrDefault().DeptTeamGUID)
.FirstOrDefault().Name
Can anyone guide me in the right direction?