Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Adrian 38 posts 117 karma points
    Aug 16, 2013 @ 16:00

    True/False Datatype in Linq like Where(...) how to match false and DynamicNull


    I'm struggling with True/False datatype in a Linq Where query.

    I'm trying to order some articles, if they are Promoted then have them at the top and the rest follow on.

    I've added the true/false property "Promoted" late, so many many articles don't have it set.

    From razor walkthrough part5 It should return a type of DynamicNull if the property has not been set.

    I've inferred that .Where("Promoted != true) should match this DynamicNull too, but it doesn't....

    so how do I work with a true/false datatype property added late?


    var promotedContent = contentRoot.Descendants("ArticleDocType") .Where("Promoted == true") .Where("HasAccess") .OrderBy("articleDate desc") ;

    var nonPromotedContent = contentRoot.Descendants("ArticleDocType")
            .Where("Promoted != true") 
            .OrderBy("articleDate desc")
    var content = promotedContent.Concat( nonPromotedContent );
    @foreach( var n in content){                
Please Sign in or register to post replies

Write your reply to: