[SalesForce] Add List items to Map

I've created a list containing Contact ID values. I'm trying to add these values to a Contact Map which I will use to update Contact records.

I'm getting the error:
"Initial term of field expression must be a concrete SObject: LIST on this line:"
contacts.put(ocr.id, new contact(id=ocr.id, Major_Gift_Prospect_Contact__c=true));

I think I understand the message after researching it. How do I modify my code so I can add list items to the map.

Thanks,

Kevin

public with sharing class AdvancementOpportunity {

    public void UpdateMajorGiftProspectContacts(){


        // Update Contact Major_Gift_Prospect_Contact__c to True if appropriate Opportunity exists.
        // Conditions: Account.Name = 'Major Gift Opportunity' and DEPARTMENT_TYPE__C = 'Advancement' and DEPARTMENT_SUB_TYPE__C = 'Major Gifts'
        // Need to create this as a Bulk update.

        // Create Map to hold Contact records to update
        map< id, contact > contacts = new map< id, contact >();

        // Create a list of Contacts to update:
        for(List<OpportunityContactRole> ocr: [Select contact.id from OpportunityContactRole 
                                                WHERE Opportunity.DEPARTMENT_TYPE__C = 'Advancement' 
                                                and Opportunity.DEPARTMENT_Sub_Type__C = 'Major Gifts' 
                                                and Contact.Major_Gift_Prospect_Contact__c = false ])
            {

                // Add list of contacts to add to the Contact map
                contacts.put(ocr.id, new contact(id=ocr.id, Major_Gift_Prospect_Contact__c=true));

            }

            // Update Contact records
            update contacts.values(); 

        }
}

Best Answer

Your loop variable is a List<OpportunityContactRole> when I think what you actually want it to be is just an OpportunityContactRole so that you are iterating through each of the results from your SOQL query.

Change this line:

for(List<OpportunityContactRole> ocr: ... )

To:

for(OpportunityContactRole ocr: ...)