i have a TergmGroup and under this a TermSet called "Automotive". Under this TermSet i have hierarchical Terms. How can i "query" the terms under this TermSet for two Custom Properties?

I have the following Custom Properties set for each Term in my TermStore:


I want something like this:


How could i achieve this?

1 Answer 1


Something like this has worked for me:

TaxonomySession taxSession = new TaxonomySession(rootSite);
TermStore termStore = taxSession.TermStores.DefaultIfEmpty(null).FirstOrDefault(x => x.Name == managedMetadataServiceName);
Group termGroup = termStore.Groups.DefaultIfEmpty(null).FirstOrDefault(x => x.Name == managedMetadataGroupName);
TermSet termSet = termGroup.TermSets.DefaultIfEmpty(null).FirstOrDefault(x => x.Name == managedMetadataTermSetName);

...and then you can iterate through the termset using Linq if you want with the criteria you have. For instance (this is untested code so bear with me; the pseudo-code is really what you should be interested in):

List<Term> termList = termSet.FindAll(x => x.LocalCustomProperties["ID"] == "12" && x.LocalCustomProperties["Model"] == "S600");

A couple things to note: - The LocalCustomProperties bag stores everything as a string, so if you want to do numerical work with them, you have to convert them first. - If you've set up a term hierarchy within the termset (for instance, you have 25 items under Nissan and 40 under Honda), you'd need to set up a function to run that last statement recursively to build the list.

  • Thanks, i will try and give feedback and mark as answer. I have only one termset with hierarchical terms. Therefore your solution should work.
    – BOG
    Commented Oct 25, 2015 at 16:53
  • If you have all the terms sitting at the first level you should be fine. If you have multiple levels you want to iterate through the termlist.Terms collection (and if you have more than 2 levels, you'd need to do so recursively, of course). Commented Oct 25, 2015 at 16:55
  • The terms are sitting in a hierarchie with 3 levels. I have googled and termset.getallterms would return a flat list of terms. Perhaps i dint need to iterate.
    – BOG
    Commented Oct 25, 2015 at 16:58
  • It is not possible to do a .FindAll on a TermSet. It seems that both a TermCollection and a TermSet are not LINQ'able ! Or am i wrong? (i need to use Server Side Object Model)
    – BOG
    Commented Oct 29, 2015 at 20:24
  • You might need to stuff the terms into another kind of collection first, like a list. The issue there may be that termsets are made to be multi-dimensional in nature, whereas you don't so much care about that... Commented Oct 29, 2015 at 21:34

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.