Predicates and null

Posts   
 
    
rboarman
User
Posts: 83
Joined: 01-Feb-2005
# Posted on: 27-Jul-2006 02:36:41   

Hello,

Sorry if this question is already covered somewhere.

I'm using SelfService and need to filter on null values like this:

IPredicateExpression filter = (MessagesFields.MyField == null);

"Null" doesn't work and neither does DBValue.Null.

Any help would be appreciated.

Thanks,

Rick

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 27-Jul-2006 03:37:33   

Have you tried.

IPredicateExpression filter = new PredicateExpression();
filter.Add(MessagesFields.MyField == DBNull.Value);

(MessagesFields.MyField == null) is an IPredicate and not an IPredicateExpression. IPredicateExpressions contain IPredicates.

If you want to shorten your code you can pass an IPredicate in the constructor.

IPredicateExpression filter = new PredicateExpression(MessagesFields.MyField == null == DBNull.Value);
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 27-Jul-2006 11:16:35   

In general avoid 'null' / Nothing in the field comparison predicate constructions with '==' and '!=', use DBNull.Value.

Frans Bouma | Lead developer LLBLGen Pro