1

I have some code to get the fields of a List with some Criteria.

Web web = context.Web;
List list = web.Lists.GetByTitle("Employees");
FieldCollection fieldCol = list.Fields;
context.Load(fieldCol, fields => fields.Where(field => field.Title == "Emp id").Include(field => field.Title, field => field.SchemaXml));
context.ExecuteQuery();

How to apply CAML Query of FieldCollection object like above? I need it because, in my case the 'Where' criteria is dynamic (I will compare field.Title with many names). Or other than CAML query, is there any other way that could meet my requirment?

1 Answer 1

2

Before getting into the analysis how to use CAML query instead of LINQ, better know what is the usage of CAML Query.

CAML - Collaborative Application Markup Language

CAML Query is used in various ways within the context of Microsoft SharePoint Foundation to define queries against list data. Source: MSDN

From the above statement it is very clear that the CAML Query can be applied only on list data and not on list schema, which means you may use the CAML query to proccess/filter/query the data present in the list, (ie, list items). SharePoint Fields represents the columns of a table, which means the fields are used to create a schema.

So, you cannot apply a query schema on a schema itself. This doesnt mean you cannot convert LINQ to CAML query.

To be more precise, for your requirement CAML Query cannot be applied on FieldCollection and it can be only applied for ListItemCollection.

Answer to your question:

Iterate the Field collection items using loops.

0

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.