SaaS CMS has officially launched! Learn more now.

If field value is empty how can we avoid those in the Query.Filter issue


We have "NewDetailPage" and it has an 'asset type' field. Asset type field is ContentReference type.

Now we are showing two kinds of assets in the find results by following the below approach.

query = query.FilterByExactTypes(new List<Type> { typeof(NewsroomDetailPage) });

query = query.Filter(x => !(x as NewsroomDetailPage).Asset.Match(new ContentReference(22))); // news releases

query = query.Filter(x => !(x as NewsroomDetailPage).Asset.Match(new ContentReference(9987))); //videos

But how can we exclude the if the Asset Type field was empty?

Jan 11, 2024 11:06

If it's empty I'd imagine it'll be ContentReference.Empty so I'd suggest writing and exclude filter for any that match that.

Jan 11, 2024 15:56

query = query.Filter(x => !(x as NewsroomDetailPage).Asset.Match(ContentReference.Empty)); should work as Scott suggested 

or you can write something like

        public static FilterExpression<ContentReference> IsEmpty(this ContentReference value)
            return new FilterExpression<ContentReference>(x => ContentReference.IsNullOrEmpty(x));

Jan 12, 2024 12:27
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.