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

Forums / Developing with Sitefinity / Ordering products by custom field

Ordering products by custom field

8 posts, 0 answered
  1. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    20 Mar 2013
    Link to this post
    I'm sure this is possible but I'm struggling to get it working. I have a custom field ("Ordinal") created in each of my product types. In my product select query I'm trying to order the products by this value using:

    catManager.GetProducts().Where(p => p.GetValue<TrackedList<Guid>>("Department").Contains(Department.Id) && p.IsActive).OrderBy(p => p.GetValue<decimal?>("Ordinal"));

    Unfortunately I only get this error:

    Database mapped field does not exist.
    Parameter name: methodCallExpression
    Actual value was p.FieldValue("Ordinal").

    What's the correct syntax for implementing this ordering?

    thanks
  2. Randy Hodge
    Randy Hodge avatar
    96 posts
    Registered:
    03 Nov 2014
    23 Mar 2013
    Link to this post
    Hi Nick,

    I have answered you in your support ticket.

    Kind regards,
    Randy Hodge
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    12 Apr 2013
    Link to this post
    For everyone else who experiences this here is the outcome. This is bug, a workaround is to include .ToList() in the statement, e.g.

    var products = catalogMgr.GetProducts().Where(p => p.IsActive).ToList().OrderBy(p =>
    p.GetValue<Decimal>("NumberField1"));

    Also, it's in PITS to vote and track here: http://www.telerik.com/support/pits.aspx#/public/sitefinity/14755
  4. Collin
    Collin avatar
    2 posts
    Registered:
    11 Oct 2013
    02 May 2014
    Link to this post

    Is this bug resolved yet? Because this means you have to materialize the collection before you can filter it, which is a major performance issue if you have large quantities of data.

  5. Wilko
    Wilko avatar
    6 posts
    Registered:
    30 Aug 2013
    02 May 2014
    Link to this post

    I would cry from happiness if there is a proper solution for this

  6. Atanas Valchev
    Atanas Valchev avatar
    414 posts
    Registered:
    04 Jan 2016
    07 May 2014
    Link to this post
    Hello,

    In order to make this work you have to specify on which product type this custom field is. For example: CatalogManager.GetManager("catalogProvider15").GetProducts("Telerik.Sitefinity.DynamicTypes.Model.sf_ec_prdct_testproducttype").Where(p => p.OriginalContentId != Guid.Empty && p.GetValue<string>("customFieldString") != "string1").OrderBy(p => p.GetValue<DateTime?>("testDate")).ToList();

    This way, you do not have to load the whole collection before doing it. 

    I hope this helps.

    Regards,
    Atanas Valchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  7. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    07 May 2014 in reply to Atanas Valchev
    Link to this post

    That may work for a single product type, but in our situation we needed products from multiple product types, and to order them using a custom field that exists for every product type.

  8. Wilko
    Wilko avatar
    6 posts
    Registered:
    30 Aug 2013
    07 May 2014
    Link to this post

    We only have one type of product in our site so this solution saved me!! Thanks

8 posts, 0 answered