String.IsNullOrEmpty in LINQ To SQL query?
I don't know if that works, but I'm sure this does:
where (result.Info ?? "") != ""
(strongly recommend the parens, query generator can get confused without them)
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;
It is not supported since attempting to use it results in a NotSupportedException
being thrown with this message:
Method 'Boolean IsNullOrEmpty(System.String)' has no supported translation to SQL.
Instead, you can use this approach to do the same thing:
var results = from result in context.Records
where result.Info != null && result.Info.Length > 0
select result;
You may also use result.Info != String.Empty
instead of checking the length. Both approaches will work.