DocumentQuery to get pages that faill within a specific year

mun yung kan asked on December 14, 2015 07:25

Hey Guys,

i'm trying to achieve a query that would get me pages that match a year specified in the page's form controls.

currently i end my query with a linq where statement, which means i cannot paginate after.

                            .Path(CurrentDocument.NodeAliasPath, PathTypeEnum.Children)
                            .Where(n => n.GetValue("MyDateValue", DateTime.MinValue).Year == 2015);

what function could i use to achieve the same result, and allow me to use the .Page(x,x) function?

Correct Answer

mun yung kan answered on December 15, 2015 05:34

Hi Brenden,

indeed that allows me to use the pagination function, however the WhereGreaterOrEquals will match anything that is the provided year and ahead of that.

of course WhereEquals does not work as well, since i am not able to instruct it to match only the year (it will look for the exact field of the "MyDateValue" field, which is a datetime.

managed to solve this with there WhereLike function

WhereLike("MyDateValue", string.format("%{0}%", year))

gets me my results filtered properly, as well at allows me to paginate.

thanks for the push in the right direction!

0 votesVote for this answer Unmark Correct answer

Recent Answers

Brenden Kehren answered on December 14, 2015 15:37

Is your field MyDateValue a DateTime datatype? If so, I'd suggest using something like this Where condition:

.WhereGreaterOrEquals("MyDateValue", DateTimeHelper.GetYearStart(DateTime.Today))

It should allow you to use .Page(1, 2) after it.

3 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.