+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Getting distict metadata values

Getting distict metadata values

5 posts, 0 answered
  1. OakTree Digital
    OakTree Digital avatar
    27 posts
    Registered:
    06 Sep 2012
    11 Mar 2011
    Link to this post
    We have some custom meta fields defined that are of the type ShortString. Does Sitefinity provide any sort of API for getting a list of distinct values for that meta field (something akin to SQL's DISTINCT keyword)?

    We've got a generic content-based-module with about 5000 items in it and would like to generate a list of distinct values for a particular metafield to bind to a dropdown list for filtering purposes.

    So far, the only solution we can see is getting all content items, looping through them, and building a list of distinct values. We're getting pretty poor performance from this approach, so we are hoping that there's a better way...

    Thanks!
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    14 Mar 2011
    Link to this post
    Hello Stuart,

    The metafiled is part of the content item, so you need to get the content item and then check the meta value. You can use LINQ
     .Distinct();
    which has Distinct() method.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. OakTree Digital
    OakTree Digital avatar
    27 posts
    Registered:
    06 Sep 2012
    14 Mar 2011
    Link to this post
    unfortunately this is also very slow with 5000 items. From within our manager class we have the following defined :



    private List<string> _manufacturers;
    public List<string> Manufacturers {
        get {
            if (this._manufacturers == null) {
                IEnumerable<IContent> content = this.Content.GetContent().Cast<IContent>();
     
                this._manufacturers = (
                    from c in content
                    select c.GetMetaData("Manufacturer").ToString()).Distinct().ToList<string>();
            }
            return this._manufacturers;
     
        }
    }
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    15 Mar 2011
    Link to this post
    Hi Stuart,

    We do not have a method that will return distinct results and the fastest way will be using the LINQ methods with some paging, where you can use Take, Skip methods.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  5. OakTree Digital
    OakTree Digital avatar
    27 posts
    Registered:
    06 Sep 2012
    24 Mar 2011
    Link to this post
    Unfortunately even this is just too slow with about 6000 items. Unfortunately we ended up having to do a direct query on the database, which is far from ideal, but performs fine.
Register for webinar
5 posts, 0 answered