Linq: checking if a string column has a value (i.e. Not empty or empty)

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

I am trying to select Contacts entries in CRM 2011, where EMailAddress1 contains a value. The following WHERE clauses I tried both threw exceptions:

Where c.EMailAddress1 > ""

Where Not String.IsNullOrEmpty(c.EMailAddress1)

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

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

But I'm just not sure if this is the most effective method. It is not very elegant. Is there an easier way to check if a row column has a value?

+5
source share
2 answers

As stated here, Linq to CRM is really limited. That is why you cannot use String.IsNullOrEmpty.

:

Where c.EMailAddress1 IsNot Nothing

, null ( ). .

,

KΓ©vin

+4

:

Where c.EmailAddress <> ""
+2

All Articles