I have an SPList with a managed metadata column and here is my caml query.
/// This caml query doesn't work
SPQuery oQuery = new SPQuery();
string strQuery = @"<Query><Where><In><FieldRef LookupId=""TRUE"" Name=""TaxonomyColumn"" /><Values><Value Type=""Text"">7392ec1d-3f35-4c5b-b6ad-f80ff15ed718</Value></Values></In></Where></Query>";
oQuery.Query = strQuery;
/// This linq query works exactly fine
var itms = (from SPListItem itm in oList.Items
where itm["TaxonomyColumn"].ToString().Contains("7392ec1d-3f35-4c5b-b6ad-f80ff15ed718")
select itm).ToList();
My problem is I need to use CAML Query for some reason and I can’t just figure out a way on how to compose my CAML Query to work on querying a list where the column is a managed metadata column.
Please help me. Thanks.
You don’t use the GUID, you need to use the lookup the id. You find this id using TaxonomyField.GetWssIdsOfKeywordTerm(), and write CAML like this:
“In” is a convenience when there are multiple values instead of multiple Eq/Or statements.
Explained in detail here:
http://msdn.microsoft.com/en-us/library/ff625182.aspx