This project is read-only.

max() statement

Mar 14, 2009 at 2:38 PM
I can't find docs about how to build filter to retrieve the content item with max id.
There is no max() statement using syntax "N2.Find.Items.Where.Type.Eq(typeof(Volunteer)).And.ID".
Anybody knows?
Mar 14, 2009 at 4:05 PM
How about something like this?

Mar 14, 2009 at 8:31 PM
Oct 14, 2009 at 3:44 PM

My question seems to be close to this one

I will appreciate your help with such query

        IQueryEnding query = N2.Find.Items
            .Filters(new NavigationFilter(), new PageFilter(), new AccessFilter())

I want to get last 3 BookItems, but the query returns me all - MaxResults seems not to work for me

Oct 14, 2009 at 11:06 PM

Could you try reproducing this in a unit test and post it?

Oct 15, 2009 at 8:59 AM
Edited Oct 15, 2009 at 6:01 PM


I tried to make test inside N2.Tests.Persistence.NH.ItemFinderTests

        public void FilterByTypeWithMaxResults()
            IList<ContentItem> items = finder.Where.Type.Eq(typeof(PersistableItem2)).MaxResults(1).OrderBy.Published.Desc.Select();
            Assert.AreEqual(1, items.Count);

It works OK.

BUT still in my code the simplified query like

private IQueryEnding CreateQuery()
        IQueryEnding query = N2.Find.Items.All.MaxResults(1);
        return query;

returns all items


Oct 15, 2009 at 5:57 PM
Edited Oct 15, 2009 at 6:00 PM


when I changed code from using Query to binding DataSource directly to Repeater it works

protected override void OnInit(EventArgs e)
        this.LastBooksRepeater.DataSource = N2.Find.Items
            .Filters(new NavigationFilter(), new PageFilter(), new AccessFilter())

Can you lead me where can I write test specifically for IQueryEnding?


Oct 15, 2009 at 7:53 PM

IQueryEnding is part of the finder so ItemFinderTests is a good place.

Oct 15, 2009 at 10:31 PM

I have found out what was my mistake. Just specifying Query for ItemDataSource doesn't really provide changes to the result set of objects.

Thank you.