Querying relationships with LinqtoCRM
I’ve just recorded a web cast demontrating joins with LinqtoCRM. The piece de resistance is a join across a many-to-many relationship with the intermediary class generated by CRMMetal:
var res = from u in p.Linq() join sr in p.Linq() on u.systemuserid.Value equals sr.systemuserid.Value join r in p.Linq() on sr.roleid.Value equals r.roleid.Value select new { u.fullname, r.name };
The equivalent example query in the CRM SDK is around forty lines, compared to four for LinqtoCRM. Watch the web cast here.
8 thoughts on “Querying relationships with LinqtoCRM”-
-
-
Pingback: Randoom – LinqtoCRM competitor and new version
-
-
-
-
-
Guil says:
Good stuff 🙂
Do you plan to add support to custom entities?
Cheers,
friism says:
@Guil, custom entities are supported out of the box, the example just uses a standard entity for common frame of reference.
brenden says:
I have an example below of code I have tried to use that is very similar to your demo. It compiles and it authenticates but when the result returns I get a message “Server was unable to process your request”.
Any ideas at all?
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = “QSM”;
CrmService service = new CrmService();
service.Url = “http://qsmcrm:5555/qsm/mscrmservices/2007/CrmService.asmx”;
service.Credentials = new NetworkCredential(“administrator”, “[email protected]”, “crm”);
ICrmService s = new CrmWebService(service);
CrmQueryProvider p = new CrmQueryProvider(s);
var res = from c in p.Linq()
select c.fullname;
foreach (var i in res)
{
Response.Write(i);
}
friism says:
Does the crmqueryprovider work if you don’t use linqtocrm? I.e. can you do a standard query? Otherwise I haven’t a clue.
Brian says:
@brenden
Use the MetadataService, not CrmService
service.Url = “http://qsmcrm:5555/qsm/mscrmservices/2007/MetadataService.asmx”;
Thomas says:
Is there a chance to do something like paging?
I have to retrieve all contacts (about 500 000) and import them in a third party system using the webservice provided.
any idea?
admin says:
@Thomas, yes — there’s even an example here: http://linqtocrm.codeplex.com/wikipage?title=Querying%20CRM%20with%20Linq&referringTitle=Home