Search

Tuesday, May 11, 2010

LINQ on CRM SDK 4.0.12

  1. Download here.
  2. Generate linq code for CRM, from a command line – go to the SDK folder/Microsoft.xrm/Tools and run the following command line – replacing MyCrmServer with your actual server name, replace MyCrmOrg with your actual CRM Org and MyEntitiesFolder with the name. Note : This assumes using integrated authentication for on-premise – support is available for many different scenarios – check the docs.
crmsvcutil /connectionString:"Authentication Type=AD; Server=http://servername/crm_orgname; User ID=domain\username; Password=password;" /out:"C:\Entities"


I’m very excited to talk about the new LINQ to CRM libraries available recently. Say you need to retrieve an Account Number, given the Account Name…

Using the traditional webservice methods:

ColumnSet cols = new ColumnSet();
cols.AddColumns(new string[] {"accountnumber"});

QueryByAttribute query = new QueryByAttribute();
query.ColumnSet = cols;
query.EntityName = "account";
query.Attributes = new string[] {"name"};
query.Values = new string[] {"Microsoft Dynamics CRM"};

RetrieveMultipleRequest req = new RetrieveMultipleRequest();

req.Query = query;
req.ReturnDynamicEntities = true;
RetrieveMultipleResponse resp = oService.Execute(req) as RetrieveMultipleResponse;
BusinessEntityCollection becMultipleRecords = resp.BusinessEntityCollection;
if (deSalesOrder.Properties.Contains("accountnumber"))
{
//And So On
//And So Forth
}

Using LINQ to SQL:

var accounts = (from a in context.Accounts
where a.Name.Equals("Microsoft Dynamics CRM")
select a).ToList();
LINQ2CRM.Account acc = (Account)accounts.First();
Response.Write("Account name = " + acc.Name.ToString());

No comments:

Post a Comment