Reputation: 637
Am using EF 6.1.1 in C# Windows Forms Application and facing strange issues on Performance factor.
My database has a table with name Ticket
and has 49300 records. This table has multiple other tables linked. Entity Framework diagram is available at: https://i.sstatic.net/3Lgyb.png
The record counts are as follows:
BillableOption 4 Company 390 Contact 687 Location 3 Member 16 ServiceBoard 6 ServiceItem 0 ServicePriority 8 ServiceSource 5 ServiceStatus 93 ServiceSubType 668 ServiceType 20 Ticket 49300 TimeEntry 52518 TimeEntryMember 0 WorkRole 10 WorkType 5
My EF Data Context is globally available as a static variable of a class. When I fire following code, it takes 12-15 seconds to load data (only talking about .ToList()
method). and bind with DataGridView. Is there any way to increase the performance?
public static List LoadTicket() { bool lastValue1 = DataAccessLocal.dc.Configuration.AutoDetectChangesEnabled; bool lastValue2 = DataAccessLocal.dc.Configuration.ProxyCreationEnabled; DataAccessLocal.dc.Configuration.AutoDetectChangesEnabled = false; DataAccessLocal.dc.Configuration.ProxyCreationEnabled = false; var returnValue = (from r in DataAccessLocal.dc.Tickets.AsNoTracking() select new LinqTicket { Summary = r.Summary, DetailDescription = r.Summary, Resolution = r.Resolution, CompanyName = r.Company.CompanyName, ContactName = (r.Contact == null ? string.Empty : r.Contact.FirstName + " " + r.Contact.LastName), BoardName = r.ServiceBoard.ServiceBoardName, Priority = r.ServicePriority.ServicePriorityName, Source = r.ServiceSource.ServiceSourceName, Location = r.Location.LocationName, ServiceType = r.ServiceTypeRecId == null ? string.Empty : r.ServiceType.ServiceTypeName, ServiceSubType = r.ServiceSubTypeRecId == null ? string.Empty : r.ServiceSubType.ServiceSubTypeName, ServiceItem = r.ServiceItemRecId == null ? string.Empty : r.ServiceItem.ServiceItemText, StatusName = r.ServiceStatus.ServiceStatusName, TicketRecId = r.TicketRecId, RemoteTicketId = r.RemoteTicketRecId.Value, DueDate = r.RequiredDate == null ? new DateTime(1900, 1, 1) : r.RequiredDate.Value, EstimatedHours = r.BudgetHours == null ? 0 : r.BudgetHours.Value, ServiceBoardId = r.ServiceBoard.ServiceBoardRecId, InternalStatus = r.InternalStatus.HasValue == true ? (enmInternalStatus)r.InternalStatus.Value : enmInternalStatus.OK, LastUpdatedByMemberRecId = r.LastUpdatedByMemberRecId }).ToList(); DataAccessLocal.dc.Configuration.AutoDetectChangesEnabled = lastValue1; DataAccessLocal.dc.Configuration.ProxyCreationEnabled = lastValue2; return returnValue; }
Upvotes: 0
Views: 439
Reputation: 101
If you really need to bind that many records to the DataGridView, you should use Virtual Mode.
Quote from msdn Implementing Virtual Mode with Just-In-Time Data Loading in the Windows Forms DataGridView Control:
One reason to implement virtual mode in the DataGridView control is to retrieve data only as it is needed. This is called just-in-time data loading.
Upvotes: 1