通过 CRM Web 服务更新 Dynamics CRM 4 中的实体需要很长时间
我在使用 Dynamics CRM 4 时遇到了一些问题。我尝试使用 WPF 应用程序中的 crm 服务更新价格和可用性,但需要很长时间。长达半小时,约 6000 个产品。需要花这么长时间吗?我可以用其他更快的方式做到这一点吗?
QueryExpression query = new QueryExpression();
query.EntityName = EntityName.product.ToString();
BusinessEntityCollection entities = crmService.RetrieveMultiple(query);
foreach (product crmProduct in entities.BusinessEntities.OfType<product>())
{
crmProduct.price = new CrmMoney() { Value = 123M };
crmProduct.stock = new CrmNumber() { Value = 123 };
crmService.Update(crmProduct);
}
Im having some trouble with Dynamics CRM 4. Im trying to update prices and availability with the crm-service in a WPF-app but it takes forever. Up to half an hour with about 6000 products. Should it take so long? Can I do this in some other quicker way?
QueryExpression query = new QueryExpression();
query.EntityName = EntityName.product.ToString();
BusinessEntityCollection entities = crmService.RetrieveMultiple(query);
foreach (product crmProduct in entities.BusinessEntities.OfType<product>())
{
crmProduct.price = new CrmMoney() { Value = 123M };
crmProduct.stock = new CrmNumber() { Value = 123 };
crmService.Update(crmProduct);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了提高性能,请尝试仅更新您真正想要更新的字段。您的代码正在更新每个属性,因为您正在使用来自 CRM 的产品。当您执行此操作时,每个插件都会被触发,并且由于产品是核心 CRM 实体,因此在更新此实体时可以触发更多 CRM 逻辑。
尝试仅获取产品的主键(productid)并设置这两个字段并调用更新语句。这样,当使用顺序进程时,您应该在标准硬件上实现每秒大约 100 个请求。
要实现更多更新,请尝试在 CRM 服务器上运行该流程或使用并行处理。
To improve performance, try to update only the fields that you really wan to update. Your code is updating every attribute, because you are using the product that comes from CRM. When you are doing that every plugins are fired and because product is a core CRM entity, more CRM logic can be fired when updating this entity.
Try to get only the primary key of product (productid) and set both fields and call the update statement. With this, you should achieve about 100 requests per second on standard hardware when using a sequential process.
To achieve more updates, try running the process on the CRM server or using parallel processing.
尝试在您的 CRM 服务对象上设置此选项:
这使得服务仅进行一次身份验证,然后使用相同的凭据。如果代码位于多个人将使用同一个 CRM 服务的网站中,这将是一件坏事,因为未来的用户可以访问他们不应该访问的记录,但是,在只有一个的 WPF 应用程序中用户,这不是问题。
这里有一篇文章更多指标和更多需要考虑调整的事情。它最初适用于 CRM 3,但我们发现 4 中的相同设置仍然可以提高性能。
Try setting this on your CRM Service object:
This makes the service only authenticate once, then uses the same credentials. This would be a bad thing if the code were in a web site where multiple people were going to be using the same CRM Service, as future users could get access to records they shouldn't, however, in a WPF app where there's just one user, this isn't a concern.
Here's an article with more metrics and some more things to think about tweaking. It originally applies to CRM 3, but we've found the same settings in 4 still boost performance.