private void LoadDataToUi() { IList <MessageSummaryModel> data = new List <MessageSummaryModel> { new MessageSummaryModel { EntityId = (int)Entity.Product, EntityName = "Products", CompleteCount = 0, PendingCount = 0, ErrorCount = 0 }, new MessageSummaryModel { EntityId = (int)Entity.SalesOrder, EntityName = "Sales Orders", CompleteCount = 0, PendingCount = 0, ErrorCount = 0 }, new MessageSummaryModel { EntityId = (int)Entity.Customer, EntityName = "Customers", CompleteCount = 0, PendingCount = 0, ErrorCount = 0 }, new MessageSummaryModel { EntityId = 0, EntityName = "Others", CompleteCount = 0, PendingCount = 0, ErrorCount = 0 }, }; var searchData = new MessageSearchModel { CreatedFrom = DateTime.Today.AddDays(-FromDateSelected), CreatedTo = DateTime.Today.AddDays(1) }; IList <MessageCountModel> databaseData = localSql.GetErpMessageSummary(searchData); EntityCount = localSql.GetReverseEntities().Count; if (databaseData.Count > 0) { (from c1 in databaseData join c2 in data on c1.EntityId equals c2.EntityId select c1.StatusId == (int)MessageStatus.Complete ? c2.CompleteCount = c1.Count : c1.StatusId == (int)MessageStatus.Error ? c2.ErrorCount = c1.Count : c2.PendingCount += c1.Count).ToArray(); (from c1 in databaseData from c2 in data where c2.EntityId == 0 & c1.EntityId != (int)Entity.Customer & c1.EntityId != (int)Entity.SalesOrder & c1.EntityId != (int)Entity.Product select c1.StatusId == (int)MessageStatus.Complete ? c2.CompleteCount += c1.Count : c1.StatusId == (int)MessageStatus.Error ? c2.ErrorCount += c1.Count : c2.PendingCount += c1.Count).ToArray(); } ReportData.Clear(); ReportData.AddRange(data); }