This project is read-only.

Exclude trash items

Topics: Developer Forum
Oct 16, 2008 at 9:01 AM


When I query items like in the following example, I also retrieve deleted items from the trash.
How can I avoid deleted items in my result?

public System.Collections.Generic.IList<Course> GetAll()


        System.Type courseType = typeof(Course);

        N2.Collections.ItemFilter[] filters = Helper.GetFrontendFilters(courseType);


        System.Collections.Generic.IList<Course> courses = null;

        courses = N2.Find.Items






        return courses;



Oct 16, 2008 at 10:20 AM
ItemFilter isNavigatable = new NavigationFilter();
in your FrontEndFilters?

That would do the trick I think.
Oct 17, 2008 at 7:51 AM

It worked!  I knew I was missing a filter… I could just not figure out which one :o)

The reason of why I haven’t added the NavigationFilter  is, that the documentation says that it’s a composition of page, visible, published and access filter (don't I already have those?).

public static N2.Collections.ItemFilter[] GetFrontendFilters(System.Type contentType)
    N2.Collections.ItemFilter[] filters = new N2.Collections.ItemFilter[]
        new N2.Collections.PublishedFilter(),
        new N2.Collections.AccessFilter(),
        new N2.Collections.PageFilter(),
        new N2.Collections.VisibleFilter(),
        new N2.Collections.TypeFilter(contentType)

    return filters;

Apr 23, 2009 at 10:22 AM
Edited Apr 23, 2009 at 10:24 AM
Similar question: I don't want to retrieve items that are in the trash but I do want all items regardless of the date they were published... visible properties etc...
This works fine:
List<MyCustomItem> allItems = (List<MyCustomItem>) N2.Find.Items.Where.Type.Eq(typeof(MyCustomItem)). Select<MyCustomItem>();

The query as returned at line 252 from QueryBuilder.cs:
QueryString = "
select ci from ContentItem ci where VersionOfID Is Null and (  ci.class  =  :v0)This returns 0 items:

This returns 0 items: 

List<MyCustomItem> allItems =

public class Helper
    public static N2.ContentItem TrashCan {
        get {
            N2.ContentItem ci = N2.Context.Persister.Get<N2.ContentItem>(505);
            return ci;

result: QueryString = "select ci from ContentItem ci where VersionOfID Is Null and (  ci in (select cd.EnclosingItem from ContentDetail cd where cd.BoolValue  =  :v0 AND cd.Name = :n0)) order by Published desc"

Any idea why this doesn't work?
Any better solutions?


Apr 23, 2009 at 5:50 PM
From the hql query you posted I would have thought the fluent line would look something like this:


Are you sure you posted the correct one?

Also, you still run the risk of including thrown items as long as they are not directly below the trash, e.g. if you delete a complete structure. An idea might be filtering by parent or devising some property that marks deleted nodes.