In Orchard CMS, how can I get all items of a particular content type based in the values of an attached part's properties

StackOverflow https://stackoverflow.com/questions/22699848

  •  22-06-2023
  •  | 
  •  

Question

I'm using Orchard 1.7.2.

I have created a new content type called PropertyImage of stereotype Media. I also created a part called PropertyPart and attached that part to my PropertyImage content type. This allows a user to pick a product when uploading a PropertyImage (ie to say 'This image is of this property').

So far so good.

Now what I'd like to do is query for all PropertyImages that have a PropertyPart attached to them where the associated property is x, y, or z.

This is what I have so far:

var images = _orchardServices.ContentManager
    .Query<PropertyPart, PropertyRecord>()
    .Where(p => p.PropertyId == id)
    .ForType(new[] { "PropertyImage" });

This however will only return a collection of PropertyParts, which is not what I want, because I want the whole PropertyImage Content Item. How can I do this?

I should point out that properties come from an external source, and are therefore not content items.

Edit

As soon as I asked this question, I realised I could just append my query with this:

.List().Select(p=>p.ContentItem)

Sometimes it just helps to talk your problem through!

Était-ce utile?

La solution

As soon as I asked this question, I realised I could just append my query with this:

.List().Select(p=>p.ContentItem)

Sometimes it just helps to talk your problem through!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top