I've been struggling with writing Linq queries against the Dynamics CRM 2015 SDK OrganizationServiceContext
. I'm finding that often the Linq methods I want to use are not supported by the CRM Linq Provider.
The latest is Count()
. I have an IQuerable<Lead>
object and want to count the total records that would be returned when enumerated. But calling Count()
on an IQueryable
gives the error:
The method 'Count' is not supported
Digging around I found this advice which is to define the Linq query as an IEnumerable
. This appears to work - calling Count()
on the IEnumerable<Lead>
object returns the total records.
What I'd like to know is where the enumeration operation takes place. Is it Dynamics side, or is it pulling all leads into my web server memory and counting there? The whole reason I'm performing the count in the first place is to guard against pulling too large a dataset into memory...