当前位置: 首页>>代码示例>>C#>>正文


C# XrmServiceContext.Execute方法代码示例

本文整理汇总了C#中XrmServiceContext.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# XrmServiceContext.Execute方法的具体用法?C# XrmServiceContext.Execute怎么用?C# XrmServiceContext.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XrmServiceContext的用法示例。


在下文中一共展示了XrmServiceContext.Execute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SavedQueries

        public static void SavedQueries(XrmServiceContext svcContext)
        {
            QueryExpression mySavedQuery = new QueryExpression
            {
                ColumnSet = new ColumnSet("savedqueryid", "name", "querytype", "isdefault", "returnedtypecode", "isquickfindquery"),
                EntityName = SavedQuery.EntityLogicalName,
                Criteria = new FilterExpression
                {
                    Conditions =
                    {
                        new ConditionExpression
                        {
                            AttributeName = "querytype",
                            Operator = ConditionOperator.Equal,
                            Values = {0}
                        },
                        new ConditionExpression
                        {
                            AttributeName = "returnedtypecode",
                            Operator = ConditionOperator.Equal,
                            Values = {SalesOrder.EntityTypeCode}
                        }
                    }
                }
            };
            RetrieveMultipleRequest retrieveSavedQueriesRequest = new RetrieveMultipleRequest { Query = mySavedQuery };

            RetrieveMultipleResponse retrieveSavedQueriesResponse = (RetrieveMultipleResponse)svcContext.Execute(retrieveSavedQueriesRequest);

            DataCollection<Entity> savedQueries = retrieveSavedQueriesResponse.EntityCollection.Entities;

            using (StreamWriter sw = new StreamWriter(crmPath + "SavedQueries.txt"))
            {
                //Display the Retrieved views
                String oo = "Open Orders (Support)";
                SavedQuery sq = new SavedQuery();
                sw.WriteLine("rsq.SavedQueryId;rsq.Name;rsq.QueryType;rsq.IsDefault;rsq.ReturnedTypeCode;rsq.IsQuickFindQuery");
                foreach (Entity ent in savedQueries)
                {
                    SavedQuery rsq = (SavedQuery)ent;
                    sw.WriteLine("{0};{1};{2};{3};{4};{5}", rsq.SavedQueryId, rsq.Name, rsq.QueryType, rsq.IsDefault, rsq.ReturnedTypeCode, rsq.IsQuickFindQuery);
                    if (rsq.Name.Equals(oo))
                        sq = rsq;
                }
                sw.WriteLine("*****************");
                sw.WriteLine("FetchXml: " + sq.FetchXml);
                sw.WriteLine("ColumnSetXml: " + sq.ColumnSetXml);
                //sw.WriteLine("CreatedBy: " + sq.CreatedBy.Name);
                sw.WriteLine("Description: " + sq.Description);
                sw.WriteLine("QueryAPI: " + sq.QueryAPI);
                sw.WriteLine("ReturnedTypeCode: " + sq.ReturnedTypeCode);

                ExecuteByIdSavedQueryRequest executeSavedQueryRequest = new ExecuteByIdSavedQueryRequest()
                {
                    EntityId = sq.Id
                };

                // Execute the request
                sw.WriteLine("  Executing Saved Query");
                ExecuteByIdSavedQueryResponse executeSavedQueryResponse =
                    (ExecuteByIdSavedQueryResponse)svcContext.Execute(executeSavedQueryRequest);

                // Check results
                if (String.IsNullOrEmpty(executeSavedQueryResponse.String))
                    throw new Exception("Saved Query did not return any results");

                sw.WriteLine(executeSavedQueryResponse.String);

            }
        }
开发者ID:Phil-Ruben,项目名称:CRM,代码行数:70,代码来源:CrmCalls.cs

示例2: Run

        /// <summary>
        /// This method first creates a series of Accounts to query over, a user query 
        /// that retrieves the names of all Accounts with a name of 'Coho Winery' and 
        /// a system query that retrieves all Account names. Then it validates the system 
        /// query, executes the system query and displays the results, and finally 
        /// executes the user query and displays the results.
        /// </summary>
        /// <param name="serverConfig">Contains server connection information.</param>
        /// <param name="promptforDelete">When True, the user will be prompted to delete all
        /// created entities.</param>
        public void Run(XrmServiceContext _serviceProxy, bool promptforDelete)
        {
            try
            {
                // Connect to the Organization service.
                // The using statement assures that the service proxy will be properly disposed.
                using (_serviceProxy)
                {
                    // This statement is required to enable early-bound type support.
                    ///_serviceProxy.EnableProxyTypes();

                    CreateRequiredRecords();

                    #region Validate saved query

                    // Create the request
                    ValidateSavedQueryRequest validateRequest = new ValidateSavedQueryRequest()
                    {
                        FetchXml = _savedQuery.FetchXml,
                        QueryType = _savedQuery.QueryType.Value
                    };

                    // Send the request
                    Console.WriteLine("  Validating Saved Query");
                    try
                    {
                        // executing the request will throw an exception if the fetch xml is invalid
                        var validateResponse = (ValidateSavedQueryResponse)_serviceProxy.Execute(validateRequest);
                        Console.WriteLine("  Saved Query validated successfully");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("  Invalid Saved Query");
                        throw;
                    }

                    #endregion

                    #region Execute saved query

                    // Create the request
                    ExecuteByIdSavedQueryRequest executeSavedQueryRequest = new ExecuteByIdSavedQueryRequest()
                    {
                        EntityId = _savedQuery.Id
                    };

                    // Execute the request
                    Console.WriteLine("  Executing Saved Query");
                    ExecuteByIdSavedQueryResponse executeSavedQueryResponse =
                        (ExecuteByIdSavedQueryResponse)_serviceProxy.Execute(executeSavedQueryRequest);

                    // Check results
                    if (String.IsNullOrEmpty(executeSavedQueryResponse.String))
                        throw new Exception("Saved Query did not return any results");

                    PrintResults(executeSavedQueryResponse.String);
                    #endregion

                    #region Execute user query

                    // Create the request
                    ExecuteByIdUserQueryRequest executeUserQuery = new ExecuteByIdUserQueryRequest()
                    {
                        EntityId = _userQuery.ToEntityReference()
                    };

                    // Send the request
                    Console.WriteLine("  Executing User Query");
                    ExecuteByIdUserQueryResponse executeUserQueryResponse =
                        (ExecuteByIdUserQueryResponse)_serviceProxy.Execute(executeUserQuery);
                    if (String.IsNullOrEmpty(executeUserQueryResponse.String))
                        throw new Exception("User Query did not return any results");

                    // validate results
                    PrintResults(executeUserQueryResponse.String);

                    #endregion

                    DeleteRequiredRecords(promptforDelete);
                }
            }

            // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
            catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>)
            {
                // You can handle an exception here or pass it back to the calling method.
                throw;
            }
        }
开发者ID:Phil-Ruben,项目名称:CRM,代码行数:99,代码来源:UserQueryAndSavedQuery.cs

示例3: getInfoByGUID

 private static void getInfoByGUID(XrmServiceContext svcContext)
 {
     var request = new ExecuteByIdSavedQueryRequest
     {
         EntityId = new Guid("00000000-0000-0000-00AA-000010001002")//Account
         //EntityId =   new Guid("B1605B89-3BFE-E411-B185-6C3BE5A6CB54")
         //EntityId = new Guid("b053a39a-041a-4356-acef-ddf00182762b")//&id=%7bB1605B89-3BFE-E411-B185-6C3BE5A6CB54%7d&pagetype
     };
     var response = (ExecuteByIdSavedQueryResponse)svcContext.Execute(request);
     string resultset = response.String;
 }
开发者ID:Phil-Ruben,项目名称:CRM,代码行数:11,代码来源:Program.cs


注:本文中的XrmServiceContext.Execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。