6

I need to retrieve the key_string_value based on value of key_name. The code i am using is as below.

public void SomeFunction()
{
  Query query;
  CustomMetaKeyCriteria metaKeyCriteria = new CustomMetaKeyCriteria("page_title", Criteria.Equal);

  query=new Query( CriteriaFactory.And(pubCriteria,metaKeyCriteria));
  var j = query.ExecuteEntityQuery();
}

The list of items that i get after executing this query doesnot contains any property to fetch the key value and hence i will have to individuall call getmeta on each item id and fetch the value. Is there any alternate way using which i can get the values(to avoid so many calls to database as i believe each getmeta will hit the db)

Regards, Rajendra

1 Answer 1

6

WARNING: there is not way to get what you are seeking. You can only get the metadata objects but these do not contain connected entities (CustomMeta or RelatedKeywords). If you're interested only in the properties of resulted items then you can use the following approach

When using the Broker Query API and calling the ExecuteEntityQuery method you get the metadata objects (with no connected entities). Example:

Tridion.ContentDelivery.Meta.IItem[] results = query.ExecuteEntityQuery();
CustomMeta customMeta = null;

for (int i = 0; i < results.Length; i++)
{
    Tridion.ContentDelivery.Meta.IItem itm = results[i];
    if (itm is IComponentMeta)
    {
        IComponentMeta cm = (IComponentMeta)itm;
        customMeta = cm.CustomMeta;
    } 
    else if (itm is IPageMeta)
    {
        IPageMeta pm = (IPageMeta)itm;
        customMeta = pm.CustomMeta;
    } 
    else if (itm is IKeywordMeta)
    {
        IKeywordMeta km = (IKeywordMeta)itm;
        customMeta = km.CustomMeta;
    }
    else if (itm is ITemplateMeta)
    {
        ITemplateMeta tm = (ITemplateMeta)itm;
        customMeta = tm.CustomMeta;
    }
}

Hope this helps.

8
  • I already tried with IPageMeta but the custommeta is coming with 0 children, but if i use get meta i get the required name value collection Commented Mar 18, 2013 at 12:10
  • you're right. Looking closely at the API, that method does not load the CustomMeta or the RelatedKeywords. You will need to manually get it by yourself. Commented Mar 18, 2013 at 12:40
  • I have checked with sql profiler and its executing queryies for all the items to fetch metadata. The only thing is i am not able to fetch it from the api. Commented Mar 18, 2013 at 12:40
  • 1
    what if you enable caching for "Metadata"? That should help you a lot. You can combine this approach with calling the method ExecuteQuery which is a lot less demanding to the database. Commented Mar 18, 2013 at 13:15
  • 3
    In the cd_storage_conf.xml add this inside ItemTypes tag: <Item typeMapping="Metadata" cached="true" storageId="myStorageId"/> (change the storageId to your own). You also need to have this <ObjectCache Enabled="true">. But you also need to read the on-line docs about Caching to see how you need to set-up cache channel service (if needed). Commented Mar 18, 2013 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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