Linq: Checking if string column has a value (ie. is not null or empty)

Viewed 13911

Not sure if this is the best way to achieve this in Linq.

I'm trying to select Contact records in CRM 2011 where the EMailAddress1 contains a value. The following WHERE clauses I tried both caused exceptions:

Where c.EMailAddress1 > ""

Where Not String.IsNullOrEmpty(c.EMailAddress1)

So I ended up trying this, which seems to work ok:

Where Not c.EMailAddress1.Equals(String.Empty) _
And Not c.EMailAddress1.Equals(Nothing)

But I'm just not certain if this is the most efficient method.. it doesn't seem very elegant. Is there a neater way of checking if a string column has a value?

2 Answers
Related