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
    Adrian
    0

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

    Hi,

    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?

    Ade

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

    var nonPromotedContent = contentRoot.Descendants("ArticleDocType")
            .Where("Promoted != true") 
            .Where("HasAccess")
            .OrderBy("articleDate desc")
            ;
    
    var content = promotedContent.Concat( nonPromotedContent );
    
    @foreach( var n in content){                
        @renderArticle(n)
        }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies