This project is read-only.

Query by Field

Topics: Customizing Orchard
Mar 19, 2014 at 6:12 PM
Hey everyone,

I've searched around the forum and on internet but couldn't find an answer.

Via dashboard I've created a contentType "Wine", "Wine" has a field "Price"

I've created a Module and can query contentItems like this:

_contentManager.Query().ForVersion(VersionOptions.Published).List().Where(r => r.ContentType == "Wine").ToList();

Now I want to filter these items based on the price

Like the price less then 5€

eg cheapwine = contentManager.Query<ContentPart>("Wijn").ForVersion(VersionOptions.Published).List().Where ....

But I don't know how to get to the Field.

Can anyone help me out here?

Mar 19, 2014 at 10:19 PM
Two solutions:
  • enable the projection module and use the generated tables + hql queries to filter, this is what the Projection module is doing
  • use the search module with a dedicated index, then the search API to filter your content items
Alternately you could use a Projection directly
Mar 19, 2014 at 10:38 PM

Do you have a code example on how to do this?

For the moment I'm querying the ContentItemVersionRecord -> getting the data field and the ContentItemRecord_ID

querying My "Wine" records for the ID

Compare these two, get the value of <Price>value</Price> (by string commands) and so I get the value of my field.

This works, and It's a cool workaround :)

But I don't think this is the way to go :) This can be easier....
Marked as answer by borrierulez on 4/2/2014 at 2:20 AM