5

I am trying to sort the custom meta results based on key_date_value field. when i add the sort parameter the query is returning no result but is working fine if i remove the sort filter. The code is as below

       int month = 5;

        var v = DateTime.Now.AddMonths(-month);
        CustomMetaValueCriteria metaValueCriteria=new CustomMetaValueCriteria(v,Criteria.LessThanOrEqual);
        CustomMetaKeyCriteria metaValue = new CustomMetaKeyCriteria("ArticleDate", Criteria.Equal);
        PublicationCriteria pubCriteria=new PublicationCriteria(80);

        Criteria[] final = { metaValueCriteria, metaValue, pubCriteria };
        Query query = new Query(CriteriaFactory.And(final));


        CustomMetaKeyColumn customMetaKeyColumnDate = new CustomMetaKeyColumn("KEY_DATE_VALUE", MetadataType.DATE);
        SortParameter sortParameter = new SortParameter(customMetaKeyColumnDate, SortParameter.Descending);
       query.AddSorting(sortParameter);
        var k = query.ExecuteEntityQuery();

Thanks, Rajendra

5

Got the answer for my question from a colleague. while creating the CustomMetaKeyColumn the parameter to be provided is the value in key column and it will sort according to the value for that particular key. I was giving the name of the sql table column name and hence i was not getting the results.Changing the code below did the work

CustomMetaKeyColumn customMetaKeyColumnDate = new CustomMetaKeyColumn("Article_Date", MetadataType.DATE);

Here it will sort on key_date_value for the value having key_name as Article_Date

Thanks

  • 1
    Good catch and thanks for reporting back your solution. Since we set up the table only once and the keys and values are flexible (based on schema fields and component values), it makes sense the API (and database behind it) use pairs of keys and values. Sometimes it's good not to peek at the Database. :-) – Alvin Reyes Apr 5 '13 at 4:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.