private static DataCollection <Entity> RetrieveCRMRecords(CrmDbContext context, string primaryEntityAttribute, EntityReference reference, EntityDefinition ed, List <Guid> guids)
        {
            var fetch = ed.CreateFetch();

            //Make Retrive Multiple Query
            object[] guidArray = guids.Cast <object>().ToArray();

            var condition = new Condition(primaryEntityAttribute, ConditionOperator.In, guidArray);

            if (fetch.Entity.Filters == null || !fetch.Entity.Filters.Any())
            {
                fetch.AddFilter(new Filter
                {
                    Conditions = new List <Condition>
                    {
                        condition
                    }
                });
            }
            else
            {
                var firstFilter = fetch.Entity.Filters.FirstOrDefault();
                if (firstFilter.Conditions == null)
                {
                    firstFilter.Conditions = new List <Condition>();
                }
                firstFilter.Conditions.Add(condition);
            }

            // retrieve a fresh entity which also acts as a backend validation
            ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Calling Retrieve Multiple Request for Entity {0} ", EntityNamePrivacy.GetEntityName(reference.LogicalName)));
            RetrieveMultipleResponse responses = (RetrieveMultipleResponse)context.Service.Execute(fetch.ToRetrieveMultipleRequest());
            var entities = responses.EntityCollection.Entities;

            ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Retrieve Multiple Response for Entity {0} has Record Count {1}  ", EntityNamePrivacy.GetEntityName(reference.LogicalName), responses.EntityCollection.Entities.Count));
            return(entities);
        }