IConcurrencyPredicateFactory and Comparing Fields to NULL

Posts   
 
    
Kirk
User
Posts: 22
Joined: 26-Apr-2004
# Posted on: 24-May-2006 19:41:20   

I have run into a problem with an IConcurrencyPredicateFactory. It is as follows:


public  class PersonConcurrencyFilterFactory : IConcurrencyPredicateFactory
    {
        public IPredicateExpression CreatePredicate(
            ConcurrencyPredicateType predicateTypeToCreate, object containingEntity)
        {
            IPredicateExpression toReturn = new PredicateExpression();
            PeopleEntity person = (PeopleEntity)containingEntity;

            switch (predicateTypeToCreate)
            {
                case ConcurrencyPredicateType.Save:
                    // only for updates
                    toReturn.Add(PredicateFactory.CompareValue(PeopleFieldIndex.DrawDate,
                      ComparisonOperator.Equal, person.Fields[(int)PeopleFieldIndex.DrawDate].DbValue));
                    break;
            }
            return toReturn;
        }
    }

The problem is that it fails when comparing a person.Fields[(int)PeopleFieldIndex.DrawDate].DbValue is null. It seems this failure is due to ANSI_NULLS being on. If off all works ok. Is there some other way to code this comparison that will not fail with ANSI_NULLS on?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 25-May-2006 02:16:34   

You may want to use PredicateFactory.CompareNull when person.Fields[(int)PeopleFieldIndex.DrawDate].DbValue is null instead of PredicateFactory.CompareValue