【发布时间】:2016-10-05 03:11:03
【问题描述】:
我需要从外部表更新 CRM 数据。一切正常,但速度很慢。这是我的代码:
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();
}
}
}
有了这个,我可以在 CRM 中插入和更新数据,但速度很慢。有没有办法使用这个 Parallel.ForEach 方法或其他方法来加速这个?谢谢!
【问题讨论】:
标签: c# for-loop parallel-processing dynamics-crm-2011 dynamics-crm