开发者

How to Check for the nullable dates in the linq query

I have a array of an object of type employee,

    var s = from x in employee
                            where !string.IsNullOrEmpty(x.FirstName) && (x.FirstName.IndexOf(searchText, StringComparison.OrdinalIgnoreCase)) >= 0 || !string.IsNullOrEmpty(x.LastName) && (x.LastName.IndexOf(searchText, StringComparison.OrdinalIgnoreCase)) >= 0 ||

//I want to check here for null DateOfBirth   
x.DateOfBirth.Value.ToShortDateString().StartsWith(searchText, StringC开发者_如何转开发omparison.OrdinalIgnoreCase)
                            select x;


I think all you need is

&& x.DateOfBirth.HasValue &&

Added into your where clause to filter out dobs that are null.

I'm assuming DateOfBirth is a nullable DateTime.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜