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

Vote:
 

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?

#315458
Jan 11, 2024 11:06
Vote:
 

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.

#315463
Jan 11, 2024 15:56
Vote:
 

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));
        }

#315518
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.