Showing posts with label LINQ. Show all posts
Showing posts with label LINQ. Show all posts

Monday, 23 June 2014

Use Linq Joins (Method Syntax) with Late Binding in Ms Dynamics CRM 2011/2013

There seems to be no examples of using Linq with late binding and method syntax about, until now:

var collection = context.CreateQuery("service")
.Join(context.CreateQuery("e2_dictionary"),x => x["serviceid"], y => (y["e2_serviceid"as EntityReference).Id, (x, y) => y)
.Where(x => x["name"].Equals(serviceName));
The out of the box service entity is pretty locked down, it's not possible to add N:1 or N:N relationships, so in order to implement a classification system for the services, I created the e2_dictionary entity.

e2_dictionary has a N:1 with e2_type and service, which means that there is some validation needed in a plug-in to ensure that when that nobody creates more than one e2_dictionary and this is why the snippet above, serviceName is the name of the service :)
 
 


Thursday, 8 November 2012

Could not find an implementation of the query pattern for source type ‘type’. ‘Join’ not found. Consider explicitly specifying the type of the range variable ‘x’.

A few days back I was trying to do a join  between a ConfigurationElementCollection class, for which I had implemented IEnumerable<T> myself. The ConfigurationElement class contained a field with a guid and I was trying to get the intersect between the configuration file and a list of guids, toBeProcessed, and then return that collection of Type items. So I tried this:
Type steps = from x in plugins.Steps
            join y in toBeProcessed on x.Id equals y
            select x;
but I got this error message:
Could not find an implementation of the query pattern for source type ‘type’. ‘Join’ not found. Consider explicitly specifying the type of the range variable ‘x’.
In order to get around this issue, it is necessary to cast plugins.Steps to Type, like this:
Type steps = from x in plugins.Steps.Cast<Type>()
            join y in toBeProcessed on x.Id equals y
            select x; 
Hope it helps.