Ordering products by custom field
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
Hi Nick,
I have answered you in your support ticket.
Kind regards,
Randy Hodge
the Telerik team
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: www.telerik.com/.../pits.aspx
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.
I would cry from happiness if there is a proper solution for this
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
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.
We only have one type of product in our site so this solution saved me!! Thanks