max() statement

Mar 14, 2009 at 1: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?
Coordinator
Mar 14, 2009 at 3:05 PM
How about something like this?

N2.Find.Items.Where.Type.Eq(typeof(Volunteer)).OrderBy.ID.Desc.MaxResults(1).Select()
Mar 14, 2009 at 7:31 PM
Thanks!
Oct 14, 2009 at 2:44 PM

My question seems to be close to this one

I will appreciate your help with such query

        IQueryEnding query = N2.Find.Items
            .Where.Type.Eq(typeof(BookItem))
            .Filters(new NavigationFilter(), new PageFilter(), new AccessFilter())
            .MaxResults(3)
            .OrderBy.Published.Desc;

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

Coordinator
Oct 14, 2009 at 10:06 PM

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

Oct 15, 2009 at 7:59 AM
Edited Oct 15, 2009 at 5:01 PM

Well,

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

[Test]
        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 4:57 PM
Edited Oct 15, 2009 at 5:00 PM

Supprisingly,

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

protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        this.LastBooksRepeater.DataSource = N2.Find.Items
            .Where.Type.Eq(typeof(BookItem))
            .Filters(new NavigationFilter(), new PageFilter(), new AccessFilter())
            .OrderBy.Published.Desc
            .MaxResults(4).Select();
        this.LastBooksRepeater.DataBind();
 }

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

 

Coordinator
Oct 15, 2009 at 6:53 PM

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

Oct 15, 2009 at 9: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.