开发者

LINQ, where clause if field is int?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜