Query Content Items

Topics: Writing modules
Jul 29, 2013 at 3:35 PM
Edited Jul 29, 2013 at 4:12 PM
I have the following content part. I need to be able to get the latest record that was created by using the Date column.

I am not sure how to do this. I have an Orchard Query written to pull all of the records which works fine, but I need a subset of these (in this case, just the most recent record). I was able to create a Binding to Filter by the Date column, but this alone will not allow me to pull the most recent record.

What is the best way to implement this requirement?
            ContentDefinitionManager.AlterTypeDefinition("Results", builder =>
                builder
                    .Creatable()
                    .WithPart("CommonPart")
                    .WithPart("TitlePart")
                    .WithPart("AutoroutePart", part =>
                        part
                        .WithSetting("AutorouteSettings.AllowCustomPattern", "true")
                        .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "false")
                        .WithSetting("AutorouteSettings.PatternDefinitions", "[{Name:'Results Title', Pattern: 'results/{Content.Slug}', Description: 'results/results-title'},{Name:'Results Title', Pattern:'results/{Content.Slug}', Description:'results/results-title'}]")
                        .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")
                        ));
            
            SchemaBuilder.CreateTable("ResultsPartRecord", table => table
                .ContentPartRecord()
                .Column<string>("Date")
                .Column<string>("Name"));

            ContentDefinitionManager.AlterTypeDefinition("Results", builder => builder.WithPart("ResultsPart"));
            
            ContentDefinitionManager.AlterPartDefinition("ResultsPart", builder => builder.Attachable());
Jul 29, 2013 at 6:43 PM
You need to join on the CommonPartRecord which holds modification datetime. This is a query we're using ourselves:


_contentManager.Query(VersionOptions.Published, "MyType")
	.Join<CommonPartRecord>()
	.OrderByDescending(cr => cr.ModifiedUtc)
	.Slice(0, count /* the number of items you want to fetch */);

--


2013/7/29 CTRLIT <[email removed]>

From: CTRLIT

I have the following content part. I need to be able to get the latest record that was created by using the Date column.

I am not sure how to do this. I have an Orchard Query written to pull all of the records which works fine, but I need a subset of these (in this case, just the most recent record).

What is the best way to implement this requirement?
            ContentDefinitionManager.AlterTypeDefinition("Results", builder =>
                builder
                    .Creatable()
                    .WithPart("CommonPart")
                    .WithPart("TitlePart")
                    .WithPart("AutoroutePart", part =>
                        part
                        .WithSetting("AutorouteSettings.AllowCustomPattern", "true")
                        .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "false")
                        .WithSetting("AutorouteSettings.PatternDefinitions", "[{Name:'Results Title', Pattern: 'results/{Content.Slug}', Description: 'results/results-title'},{Name:'Results Title', Pattern:'results/{Content.Slug}', Description:'results/results-title'}]")
                        .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")
                        ));
            
            SchemaBuilder.CreateTable("ResultsPartRecord", table => table
                .ContentPartRecord()
                .Column<string>("Date")
                .Column<string>("Name"));

            ContentDefinitionManager.AlterTypeDefinition("Results", builder => builder.WithPart("ResultsPart"));
            
            ContentDefinitionManager.AlterPartDefinition("ResultsPart", builder => builder.Attachable());

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings 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