0
votes

My requirement is to get items, only from custom-columns, in a SharePoint list using LINQ.

Since my custom columns are created dynamically based on some calculations done on another SPList, it keeps increasing and decreasing in the count frequently, therefore I cannot use SPMetal.

I need to include a condition (!(SPBuiltInFieldId.Contains(field.Id))) to check if the items are taken only from custom fields in the following query.

List<SPListItem> AllResponses = (from SPListItem Response in oList.Items
                                select Response).ToList();

Please advice. Thanks!

1

1 Answers

0
votes

I'm not sure it's possible to have a list item that contains only custom columns. Even if Title is not there, you'll have ID, Modified, Created, etc. Plus, there will be a number of hidden built-in columns.

If you want a list of items that contain items with custom fields, you can try something like the following, which utilizes Where and Any methods:

List<SPListItem> AllResponses = 
    (from SPListItem Response in oList.Items select Response)
    .Where(item => item.Fields
        .Cast<SPField>()
        .Any(field => !SPBuiltInFieldId.Contains(field.Id)))
    .ToList();

This will return all items that have at least one custom field.