Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Using Parallel.ForEach for insert and update CRM data

$
0
0

Hi. I need to update CRM data from external table. All working fine but its very slow. This is my code:

static void Main(string[] args)
{
var dbClient = new CollectionEntities(); //Get database Entities
using(var xrm = new XrmServiceContext("Xrm"); // Get CRM Entities
    {
foreach (var row in dbClient.Client) //Reading rows from database
{
var c = (from a in crm.new_clientSet where a.new_Idnumber == row.Client_ID select a).FirstOrDefault(); // IS there clint with id from database
                            if (c == null)// if client not exist i create new if exists I update data
                            {
                                c = new new_client { new_Idnumber = row.Client_ID };
                                crm.AddObject(c);
                            }
                            c.new_name = row.Client_name; //[Client_name]
                            c.new_Idnumber = row.Client_ID;//[Client_ID]
                            c.EmailAddress = row.Email;//[Email]    xrm.AddObject(c);    xrm.SaveChanges();

}
}
}
With this I can insert and update data in CRM but its to slow. Is there a way to use for this Parallel.ForEach method or some other method to speed up this?  Thanks!


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>