开发者

LINQ, where clause if field is int?

开发者 https://www.devze.com 2023-02-25 18:27 出处:网络
Given the following LINQ where clause : plannedPosition.Id is of type int? pmArray is of type int[] //Works

Given the following LINQ where clause :

plannedPosition.Id is of type int?

pmArray is of type int[]

//Works
where
pmArray.Contains(plannedPosition.Id.Value)


//Does not work - will give a design time error
where
pmArray.Contains(plannedPosition.Id)
开发者_如何学编程

How can I make the query more robust to ensure that no null run type exceptions occur?


How about:

where plannedPosition.Id != null && pmArray.Contains(plannedPosition.Id.Value)
0

精彩评论

暂无评论...
验证码 换一张
取 消