private void QueryRecords()
        {
            WorkAsync("Querying Records for Selected Rows from Step 4",
                e => // Work To Do Asynchronously
                {
                    var fetchXmlBuilder = new EntityQueryBuilder();
                    var formEntryReader = new FormEntryReader(fetchXmlBuilder);
                    formEntryReader.ReadEntitySelected(entityDropdown);
                    formEntryReader.ReadUniqueIdentifierAttributes(entityAttributeView);
                    formEntryReader.ReadFilterValuesFromSelectedRow(duplicatesGrid);
                    formEntryReader.ReadDisplayAttributes(entityAttributeView);
                    var response = GetRecordsFromCrm(fetchXmlBuilder.GetOutput());

                    var reader = new FetchXmlResponseReader(response);
                    var dataset = reader.ParseEntityQueryResponse(fetchXmlBuilder);
                    SafeSetDataSource(entityRecordGrid, dataset);

                    e.Result = "Step 5 Record View Updated";
                }, e => MessageBox.Show(e.Result as string));
        }
        private void QueryRelatedRecords()
        {
            WorkAsync("Querying Related Entities for Selected Row from Step 4",
                e => // Work To Do Asynchronously
                {
                    var fetchXmlBuilder = new RelatedEntityQueryBuilder();
                    var formEntryReader = new FormEntryReader(fetchXmlBuilder);
                    formEntryReader.ReadEntitySelected(entityDropdown);
                    formEntryReader.ReadUniqueIdentifierAttributes(entityAttributeView);
                    formEntryReader.ReadFilterValuesFromSelectedRow(duplicatesGrid);
                    formEntryReader.ReadRelatedEntitySelected(relationShipDropdown);
                    fetchXmlBuilder.AddColumn(new CrmEntityAttribute("createdon", "DateTime"));
                    var response = GetRecordsFromCrm(fetchXmlBuilder.GetOutput());

                    var reader = new FetchXmlResponseReader(response);
                    var dataset = reader.ParseRelatedRecords(fetchXmlBuilder);
                    SafeSetDataSource(relatedEntityGrid, dataset);

                    e.Result = "Step 6 Record View Updated";
                }, e =>
                {
                    MessageBox.Show(e.Result as string);
                });
        }
        private void QueryDuplicates()
        {
            WorkAsync(
                string.Format("Querying Duplicates [Entity:{0} - Attributes Selected:{1}", entityDropdown.SelectedValue,
                    entityAttributeView.RowCount),
                e => // Work To Do Asynchronously
                {
                    var fetchXmlBuilder = new DuplicateQueryBuilder();
                    var formEntryReader = new FormEntryReader(fetchXmlBuilder);
                    formEntryReader.ReadEntitySelected(entityDropdown);
                    formEntryReader.ReadUniqueIdentifierAttributes(entityAttributeView);
                    fetchXmlBuilder.AddCustomFilterXml(customXMLFilterBox.Text);
                    e.Result = GetRecordsFromCrm(fetchXmlBuilder.GetOutput());

                },
                e => // Cleanup when work has completed
                {
                    var reader = new FetchXmlResponseReader(e.Result as EntityCollection);

                    var fetchXmlBuilder = new DuplicateQueryBuilder();
                    var formEntryReader = new FormEntryReader(fetchXmlBuilder);
                    formEntryReader.ReadEntitySelected(entityDropdown);
                    formEntryReader.ReadUniqueIdentifierAttributes(entityAttributeView);
                    fetchXmlBuilder.AddCustomFilterXml(customXMLFilterBox.Text);
                    var dataSet = reader.ParseGroupByResponse(fetchXmlBuilder);
                    SafeSetDataSource(duplicatesGrid, dataSet);
                });
        }