Exemple #1
0
 private void UpgradeToExecuteMultipleIfNecessary()
 {
     // If there are output columns for anything that isn't part of the Create Response, then
     // we have to upgrade to an executemultiplerequest, with an additional Retrieve to get the extra values.
     if (OutputColumns.Any())
     {
         UpgradeRequestToExecuteMultipleWithRetrieve(CurrentRequest.Target.LogicalName, CurrentRequest.Target.Id);
     }
 }
        /// <summary>
        /// Checks  the output columns. if there are output values that that aren't available from the CreateResponse, then
        /// upgrades the Request to an ExecuteMultiple request, that contains the CreateRequest, and a RetrieveRequest to
        /// to get the additional output values.
        /// </summary>
        private void UpgradeToExecuteMultipleIfNecessary()
        {
            // If there are output columns for anything that isn't part of the Create Response, then
            // we have to upgrade to an executemultiplerequest, with an additional Retrieve to get the extra values.
            if (OutputColumns.Any())
            {
                // If only a single output column, and if it's the id, then executemultiple not necessary as
                // this is already returned as the result from the createrequest.
                var targetEntity = CurrentRequest.Target;
                if (OutputColumns.Count() == 1)
                {
                    var col = OutputColumns.First();
                    IsVisitingSingleOutput = true;
                    col.ProjectionItem.Accept(this);
                    if (IsOutputSingleId)
                    {
                        return;
                    }
                }

                IsVisitingSingleOutput = false;

                // To get any other output, the id must be specified as part of the insert, so that we have the info
                // we need to do the additional retrieve request.
                if (targetEntity.Id == Guid.Empty)
                {
                    throw new NotSupportedException("An OUTPUT clause can only be used in an Insert statement, if either the INSERT specifies the ID for the new entity, or if the only Output column is the inserted entities ID.");
                }

                UpgradeRequestToExecuteMultipleWithRetrieve(targetEntity.LogicalName, targetEntity.Id);
            }
            else
            {
                // No output columns however we still automatically output the id.
                this.AddColumnMetadata(CurrentRequest.Target.LogicalName, null, CurrentRequest.Target.LogicalName + "id");
            }
        }