This project is read-only.

Creating Complex Content Parts

Topics: Customizing Orchard, Writing modules
May 4, 2011 at 4:01 AM

How would one query for ContentPartRecords using the default IContentManager instance (or anything else)?  I have a complex type like so:

  public class Part1: ContentPart<Part1Record>

       public virtual Part2Record Part2Record
            get { return Record.Part2; }
            set { Record.Part2 = value; }


I need to query for an existing Part2Record before I can create a new Part1 since Part2Record cannot be null.  I'm not sure how to get an instance of a ContentPartRecord though.  Any ideas?


May 4, 2011 at 4:35 PM

I have the same exact question, i wonder how to retrieve other contenttype items using icontentmanager interface (or the one needed). 

May 4, 2011 at 4:45 PM

I'm not sure exactly what you're after here; but are you both aware of the IContentManager.Query<TPart,TRecord>() extension methods in Orchard.ContentManagement?

May 4, 2011 at 5:12 PM

I'll check that out and let you know. What I'm looking after, mm, for example at the case when you want to dynamically access all ContentItems of a certain Type to select one and render that item. I mean, doing more than just selecting data in the dashboard. Im sure it should be straightforward, just not having the time to have a look. Ill work on this. Thanks.

May 4, 2011 at 5:55 PM

So that would be ContentManager.Query("ContentTypeName").Slice(1). There's quite a rich querying API. You can for instance also query on joined records (which is what I think the OP was basically after).

May 5, 2011 at 1:12 AM

RandomPete, I am aware of those query methods.  But how do I explicitly get a ContentPartRecord instead of an IEnumerable<ContentPart> or anything like that?

May 5, 2011 at 1:15 AM

FirstOrDefault is your friend.

May 5, 2011 at 1:25 AM

I'm still a little confused.  If I write something like _contentManager.Query<MyPart, MyPartRecord>().List().FirstOrDefault(), I still get a single object of type ContentPart not ContentPartRecord.  Can you write an example query that would return a ContentPartRecord?

May 5, 2011 at 1:34 AM

If you have the content part, you can get the record from it: it has a Record property.

May 5, 2011 at 1:51 AM

Well indeed it does.  I knew it was something obvious.  Thanks! Is there an API document I can reference?

May 5, 2011 at 2:24 AM

crjackso, im reading the API from SymbolSource, at . there some other reps too, but if theres something official that would be cool.


May 6, 2011 at 1:52 AM

Following on this, i have managed to load my desired content item in the Driver. How do i now render it? Whats the approach using the ContentManager interface?

I have got the ContentItem in my driver, and before loading the Part shape i should render the ContentItem? Or do i have to pass along to the view the ContentItem and then displaying from the view? How to do this in either case?