给定以下LINQ where子句:
plannedPosition。Id的类型是int?
pmArray的类型是int[]
//Works
where
pmArray.Contains(plannedPosition.Id.Value)
//Does not work - will give a design time error
where
pmArray.Contains(plannedPosition.Id)
如何使查询更健壮,以确保没有null运行类型异常发生?
如何:
where plannedPosition.Id != null && pmArray.Contains(plannedPosition.Id.Value)