CRM Dynamics 2013 How to Update Multiple Records From External Source Using ExecuteMultipleRequest
<p>I am having a scenario in CRM where I need to update multiple accounts values(text fields and option sets) with values from an external sql database table. How can I go about doing this using the execute multiple request. The requirement is to sync all the account data in CRM with our ERP data which comes from a sql table. This process needs to be automated so i opted to use a windows service that runs daily to update accounts that ar flagged for update in the external sql table. I am struggling to find the best approach for this,I tested this idea in a console application on DEV and here is my solution code below. My question is how can I do this better using ExecuteMultipleRequest request. </p>

<pre><code>public static void UpdateAllCRMAccountsWithEmbraceAccountStatus(IOrganizationService service, CRM_Embrace_IntegrationEntities3 db)
        {


            List&lt;C_Tarsus_Account_Active_Seven__&gt; crmAccountList = new List&lt;C_Tarsus_Account_Active_Seven__&gt;();

            //Here I get the list from Staging table
            var crmAccounts = db.C_Tarsus_Account_Active_Seven__.Select(x =&gt; x).ToList();



            foreach (var dbAccount in crmAccounts)
            {
                CRMDataObjectFour modelObject = new CRMDataObjectFour()
                {
                    ID = dbAccount.ID,
                    Account_No = dbAccount.Account_No,
                    Account_Name = dbAccount.Account_Name,
                    Account_Status = Int32.Parse(dbAccount.Account_Status.ToString()),
                    Country = dbAccount.Country,
                    Terms = dbAccount.Terms
                };
            }


            var officialDatabaseList = crmAccounts;

            //Here I query CRM to
            foreach (var crmAcc in officialDatabaseList)
            {
                QueryExpression qe = new QueryExpression();
                qe.EntityName = "account";
                qe.ColumnSet = new ColumnSet("accountnumber", "new_embraceaccountstatus");
                qe.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);
                qe.Criteria.AddCondition("accountnumber", ConditionOperator.NotIn, "List of acconts for example"


);

                EntityCollection response = service.RetrieveMultiple(qe);

                //Here I update the optionset value
                foreach (var acc in response.Entities)
                {
                    if (acc.Attributes["accountnumber"].ToString() == crmAcc.Account_No)
                    {
                        if (acc.Contains("new_embraceaccountstatus"))
                        {
                            continue;
                        }
                        else
                        {
                            acc.Attributes["new_embraceaccountstatus"] = new OptionSetValue(Int32.Parse(crmAcc.Account_Status.ToString()));
                        }
                        service.Update(acc);
                    }

                }
            }


        }
</code></pre>

<p>I know this might not be the right approach, please advise me how to use ExecuteMultipleRequest or perhaps a different solution altogether.</p>