private void PopulateParentAndChildEntities(ParentEntity parentEntity, List<ChildEntity> lstChildEntities, string unsecureConfig)
        {
            using (XmlReader reader = XmlReader.Create(new StringReader(unsecureConfig)))
            {
                reader.ReadToFollowing("ParentEntity");
                reader.MoveToAttribute("ParentEntityLogicalName");
                parentEntity.ParentEntityName = reader.Value;

                reader.MoveToAttribute("ParentActiveStateCode");
                parentEntity.ParentActiveStatecode = Convert.ToInt32(reader.Value);

                reader.MoveToAttribute("ParentInactiveStateCode");
                parentEntity.ParentInactiveStatecode = Convert.ToInt32(reader.Value);

                XDocument xmlDoc = XDocument.Parse(unsecureConfig);

                foreach (var childEntity in xmlDoc.Descendants("ChildEntity"))
                {
                    ChildEntity child = new ChildEntity();
                    child.ChildEntityName = childEntity.Attribute("ChildEntityLogicalName").Value;
                    child.PrimaryColumnName = childEntity.Attribute("PrimaryColumn").Value;
                    child.LookupSchemaName = childEntity.Attribute("LookupSchemaName").Value;
                    child.ChildActiveStatecode = Convert.ToInt32(childEntity.Attribute("ChildActiveStateCode").Value);
                    child.ChildInactiveStatecode = Convert.ToInt32(childEntity.Attribute("ChildInactiveStateCode").Value);
                    child.ChildActiveStatuscode = Convert.ToInt32(childEntity.Attribute("ChildActiveStatusCode").Value);
                    child.ChildInactiveStatuscode = Convert.ToInt32(childEntity.Attribute("ChildInactiveStatusCode").Value);

                    lstChildEntities.Add(child);
                };
            }
        }
        private static EntityCollection RetrieveChildren(IOrganizationService service, EntityReference entity, ChildEntity childEntity)
        {
            QueryExpression query = new QueryExpression();
            query.EntityName = childEntity.ChildEntityName;
            query.ColumnSet = new ColumnSet();
            query.ColumnSet.AddColumn(childEntity.PrimaryColumnName);

            ConditionExpression expr = new ConditionExpression();
            expr.AttributeName = childEntity.LookupSchemaName;
            expr.Operator = ConditionOperator.Equal;
            expr.Values.Add(entity.Id);
            query.Criteria.AddCondition(expr);

            EntityCollection children = service.RetrieveMultiple(query);
            return children;
        }