首页 > 编程语言 >用ExecuteMultiple执行多个请求 with c#

用ExecuteMultiple执行多个请求 with c#

时间:2022-12-14 13:58:05浏览次数:59  
标签:account 请求 c# sw System ExecuteMultiple new using

前言

Dynamics365中的ExecuteMultiple用来执行多个请求,比如通过控制台应用程序创建50个客户,我可以Create50次,也可以用ExecuteMultiple,1次就创建50个客户,那么两者那个创建记录耗时更短?实验如下:

1.单独创建

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Tooling.Connector;
using System;
using System.Configuration;
using System.Diagnostics;

namespace Gongdh.D365.ExecuteMultiple
{
    class Program
    {
        private static CrmServiceClient _client;

        public static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            _client = new CrmServiceClient(ConfigurationManager.ConnectionStrings["Dev"].ConnectionString);

            for (int i = 0; i < 50; i++)
            {
                Entity create_account = new Entity("account");
                create_account["name"] = $"CREATE ACCOUNT {i + 1}";
                _client.Create(create_account);
            }
            sw.Stop();
            Console.WriteLine($"程序耗时:{sw.ElapsedMilliseconds}ms.");
            Console.ReadKey();

        }
    }
}

2.ExecuteMultiple创建

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Tooling.Connector;
using System;
using System.Configuration;
using System.Diagnostics;

namespace Gongdh.D365.ExecuteMultiple
{
    class Program
    {
        private static CrmServiceClient _client;

        public static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            _client = new CrmServiceClient(ConfigurationManager.ConnectionStrings["Dev"].ConnectionString);
            ExecuteMultipleRequest request = new ExecuteMultipleRequest()
            {
                Requests = new OrganizationRequestCollection(),
                Settings = new ExecuteMultipleSettings
                {
                    ContinueOnError = false,
                    ReturnResponses = true
                }
            };

            for (int i = 0; i < 50; i++)
            {
                Entity create_account = new Entity("account");
                create_account["name"] = $"CREATE ACCOUNT {i + 1} - ExecuteMultiple";
                CreateRequest createRequest = new CreateRequest()
                {
                    Target = create_account
                };
                request.Requests.Add(createRequest); 
            }

            var response = (ExecuteMultipleResponse)_client.Execute(request);//执行

            sw.Stop();
            Console.WriteLine($"程序耗时:{sw.ElapsedMilliseconds}ms.");
            Console.ReadKey();

        }
    }
}

结论

ExecuteMultiple耗时更短。

标签:account,请求,c#,sw,System,ExecuteMultiple,new,using
From: https://www.cnblogs.com/ynysj/p/16981842.html

相关文章

  • 项目引入fastclick 导致ios中input需要多次点击才能触发focus
    main.js中引入之后的修改importFastClickfrom"fastclick";FastClick.prototype.focus=function(targetElement){letlength;if(targetElement.setSelect......
  • c++字符串和字符数组互相转
    voidmain(){//字符串转字符数组stringname="ddddd";charbuf[]={0};strcpy(buf,name.c_str());//字符串转字符数组,使用strcpycout<<n......
  • websocket携带jwt token
    在websocket中,目前未提供修改请求头字段的方法,不过可以借助于“Sec-WebSocket-Protocol”,将token放入请求头中,后端收到请求后,从请求头中取得token做校验。即:在前端websock......
  • foreach
    foreach:自动将代码置入try-finally块;若类型实现了IDispose接口,它会在循环结束后自动调用Dispose方法。 using是try-finally的语法糖。 集合版本:任何对集合进行增删......
  • 计组学习02——C and Pointers
    计组学习——CandPointers由于已经比较熟悉C了,上课时跳过了许多已经熟知的部分,只记录自己不太熟的地方。UnionsinC定义和struct基本一样unionfoo{inti......
  • crontab执行shell脚本
    shell脚本如下#!/bin/shsource/etc/profile#需要导入环境变量,否则非原生命令执行不成功procs=`ps-ef|greppython|grepaiphoto_data_maintain/bin/aiphoto_d......
  • Error in plugin @nomiclabs/hardhat-etherscan: Failed to send contract verificati
    Errorinplugin@nomiclabs/hardhat-etherscan:FailedtosendcontractverificationrequestReason:readECONNRESET//或者Reason:TIMEOUT…这个问题困扰了我......
  • Nacos-配置中心,特性,启动,集成mysql,快速入门
    Nacos-配置管理目录Nacos-配置管理1.什么是配置中心1.1什么是配置1.2什么是配置中心2Nacos****简介2.1主流配置中心对比2.2Nacos****简介2.3Nacos****特性3Na......
  • SPEL注入流程分析及CTF中如何使用
    配置https://github.com/LandGrey/SpringBootVulExploit/tree/master/repository/springboot-spel-rce,导入maven依赖为了后期debug调试简便些,可以修改一下控制器修改后运......
  • spring-cloud-alibaba-整合spring-clouid-gateway-3.1.4
    spring-cloud-alibaba-整合spring-clouid-gateway-3.1.4spring-cloud-alibaba-整合spring-clouid-gateway-3.1.4前言版本说明引入spring-cloud-gatewayspring-cloud......