Ali Adlavaran
Ali Adlavaran

Reputation: 3735

How to query ContentType that is combination of Fields (Defined by "WithField")

I've setted up a custom ContentType which is combined with other fields (such as NumericField). Now I want to create a query for this ContentType which requires applying some condition to one of combined fields. in my code i have a ContentPart called EstatePart which contains a NumericField field named "BedroomCount" :

ContentDefinitionManager.AlterPartDefinition("EstatePart", part => part.Attachable()
        .WithField(
                "BedroomCount",
                fieldBuilder =>
                {
                    fieldBuilder.OfType(typeof(NumericField).Name);        
                })

Now how i can query from EstatePart by applying a condition to BedroomCount field?

This is what i've tried:

_contentManager.Query("Estate").Where<EstatePartRecord>(r=>r. // HERE I CAN'T ACCESS TO BEDROOMCOUNT FIELD

thanks in advance.

Upvotes: 1

Views: 246

Answers (1)

Axe
Axe

Reputation: 739

The problem I believe is the Fields are not part of the ...PartReccord.

I've managed to access a Media picker field in my model like this

public MediaPickerField MediaPicker
        {
            get
            {
                return (MediaPickerField)ContentItem.As<HeaderPart>().Fields.First(x => x.Name == "Image");
            }
        }

You should be able to get the fields of the Estate type > find the one named bedroom count and query agains that. ... sorry don't know the exact syntax

Upvotes: 1

Related Questions