Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String.IsNullOrEmpty in LINQ To SQL query?

Tags:

c#

linq-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; 
like image 918
Phone Developer Avatar asked Nov 08 '11 17:11

Phone Developer


1 Answers

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; 
like image 168
user7116 Avatar answered Sep 24 '22 16:09

user7116