C# – String.IsNullOrEmpty in LINQ To SQL query

clinq-to-sql

My DBML exposes a record set that has a nullable nvarchar field. This nullable nvarchar field is represented as a string in my C# code.

Sometimes this field is null, sometimes it is an empty string, and sometimes it actually has a value.

Does String.IsNullOrEmpty() work in LINQ To SQL? For instance, would the following work:

var results = from result in context.Records
              where String.IsNullOrEmpty(result.Info) == false
              select result;

Best Answer

Curiously, per MSDN String.IsNullOrEmpty is supported (by virtue of it not being unsupported), yet I can only find complaints about it not being supported.

However, if it does work you should not explicitly compare it to a boolean value, instead:

var results = from result in context.Records
          /*XXX broke :( where !String.IsNullOrEmpty(result.Info) */
          where !(result.Info == null || result.Info.Equals(""))
          select result;