ContentManager Querying Getting Started

Topics: Core, Customizing Orchard, Writing modules
Aug 30, 2012 at 8:54 AM

Hi,

I wanted to write a widget that get's the 5 most recent news items.

I have a NewsItemPart which has a date field attached from the gui called NewsStartDate.

 

In my code behind I wanted to query and find the 5 most recent items ordered by NewsStartDate desc..

 

call me a complete newbie but I really can't find clear concise documentation on how to query using the ContentManager for a given contentpart and find a value associated with it..

what it made me realise was I really haven't found anywhere which explains the basics of querying on a given part or it's associated parts.. it makes sense where in a module you have specified properties on a part.. but what about when that part and it's property come from something you attached to make up the overall part?

 

i.e. something like contentManager.GetMany<NewsItem>().Where(ni => ni.SomeAttachedContentPart.SomeValue == "moo").OrderByDescending(ni => ni.SomeAttachedDatePart.DateFieldName).Take(5)

 

can someone give me an example please?

Thank you very much

Tom

Aug 30, 2012 at 9:29 AM

Hi Tom,

 

I'm pretty certain you want to look at the "projections" concept. I'm about to work on something very similar, I'll post back later.

Aug 30, 2012 at 11:56 AM

In the administration area

  1. Create a new Query (you can select all sorts of filters such as content type, or a field from a particular content type)
  2. Create a projection that uses this query (a projection allows the query to be rendered as a page)

but the best place to start is http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-part-5

...actually the best place to start is the first article in this guide....it is awesome.

Aug 30, 2012 at 2:03 PM

thanks so much for your replies I really appreciate it.. I've been through that tute but I'd love to know hoe to do heat I've described in code so I understand the managers and working or orchard better coming from umbraco orchard is a big learning curve

On Aug 30, 2012 8:56 PM, "LordSaul" <notifications@codeplex.com> wrote:

From: LordSaul

In the administration area

  1. Create a new Query (you can select all sorts of filters such as content type, or a field from a particular content type)
  2. Create a projection that uses this query (a projection allows the query to be rendered as a page)

but the best place to start is http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-part-5

...actually the best place to start is the first article in this guide....it is awesome.

Read the full discussion online.

To add a post to this discussion, reply to this email (orchard@discussions.codeplex.com)

To start a new discussion for this project, email orchard@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com