Sunday, June 29, 2008

Null return from iqueryable

When you do
var query = from p in db.xxx
select p;

Let's say there are two fields
FirstName and LastName

From above Query

Query.FirstName and Query.LastName are returned.

Let's say FirstName is an empty field but not Null.
LastName is Null;

FirstName is equal to both Null and string.empty.
LastName is equal to string.empty.

thus either null or string.empty can be == to string.empty

so... you can do

if ( query.FirstName == string.empty) { }
if ( query.LastName == string.empty) { }

No comments: