Follow @Lusse3 (236 followers)

Flickr Recent Photos

Soluppgången i KnivstaEn vacker morgonPalt palt i stora lass! Sara lyckades magnifikt med sin första palt sats #bArkham horrorDe gjorde bättre tidningar förr :) "gör det själv" från 1970 talet #fbPlanterar litePotatistävlingDragkampDragkampPotatistävlingMini DragkampKapten Liam

Kategorier

FindPagesWithCriteria with PropertyCriteria and PropertyDataType.Boolean set to false

Huge title but pretty much what this post is about.

To optimize your FindPagesWithCriteria, it’s good to be as specific as you can. i.e not use one criteria, get 500 hits back and then just use the top 5 out of those. Anyway, when using a PropertyDataType.Boolean and you want to get back those pages that has this set to ”false” you can’t really set the value to ”false”. Why? Because when the property is false, it has never been set which makes it null.

Let’s see the code:

PropertyCriteria crit = new PropertyCriteria{
            Condition = CompareCondition.Equal,
            Name = ContentPropertyStrings.Finished,
            Type = PropertyDataType.Boolean,
            Value = "false",
            Required = true
};

The code above won’t give you any hits since there won’t be any property set to false, because those properties are null. What you need to do is what you can see below.

PropertyCriteria crit = new PropertyCriteria{
            Condition = CompareCondition.Equal,
            Name = ContentPropertyStrings.Finished,
            Type = PropertyDataType.Boolean,
            IsNull = true,
            Required = true
};

An old problem but I still get this question from time to time so might aswell post it :)

1 Tweet

4 comments to FindPagesWithCriteria with PropertyCriteria and PropertyDataType.Boolean set to false

Kommentera

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Additional comments powered by BackType