Creating Complex Content Parts

Topics: Customizing Orchard, Writing modules
May 4, 2011 at 3: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 3: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 3: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 4: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 4: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 12: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?

Coordinator
May 5, 2011 at 12:15 AM

FirstOrDefault is your friend.

May 5, 2011 at 12: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?

Coordinator
May 5, 2011 at 12:34 AM

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

May 5, 2011 at 12: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 1:24 AM

crjackso, im reading the API from SymbolSource, at http://www.symbolsource.org/Public/Metadata/Default/Project/Orchard/1.0.20/Release/All/Orchard.Framework/Orchard.Framework/ContentManagement/IContentManager.cs . there some other reps too, but if theres something official that would be cool.

regards

May 6, 2011 at 12: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?