Use LINQ to access CRM objects
If you have written small console application to check some data from CRM database you have probably already read this article from MSDN: Use Filtered Views. That is okay but honestly I’m currently more into LINQ solution. I’ll show you what I mean...
First I'll create new Console Application project and Add New Item to it and select LINQ to SQL Classes and name it CRMDataClasses.dbml:
Then I'll use Server Explorer to connect to CRM database:
And then I'll drag Account, Contact, FilteredAccount and FilteredContact to the canvas of our newly created CRMDataClasses.dbml:
Now I'm ready to use LINQ to these views:
|
|
On lines 3 to 6 I queried all contacts that have lastname and mobilephone filled in. On lines 14 to 15 I'm querying all contacts where current user has access to. NOTE: It doesn't return anything if you use SQL Authentication! So both of these can be used to fill you applications needs. But do notice that for some reason the attributes at the FilteredContacts are all lower case and in Contacts their naming is a bit different. So if you plan to change from Contacts to FilteredContact your going to have to change the casing of the attributes little bit.
This was just quick advice how you can leverage LINQ to your CRM solutions.
Anyways... Happy hacking!
J
Comments
Anonymous
August 29, 2008
PingBack from http://blog.a-foton.ru/2008/08/use-linq-to-access-crm-objects/Anonymous
August 29, 2008
Some great information. Many ThanksAnonymous
December 10, 2008
You can also use LinqtoCRM, a free LINQ query provider for the CRM web service: http://www.codeplex.com/LINQtoCRMAnonymous
February 21, 2009
Another option is XrmLinq, works exactly like LINQ to SQL, generates code based on the CRM metadata, uses queryexpressions internally.Anonymous
April 10, 2009
FWIW, I don't know if I'd use this method. Updating data directly in the CRM database is not supported by Microsoft, but it also doesn't offer the extensibiltiy of the other options (LinqToCRM or XRMLinq). For instance, updating an etnity using the LINQ to SQL classes doesn't fire the relevant plug-ins...