[英]Entity Framework Poor Performance
enter image description here 在此处输入图片说明
Am using EF 6.1.1 in C# Windows Forms Application and facing strange issues on Performance factor. 我在C#Windows Forms Application中使用EF 6.1.1,并且在性能因素上遇到奇怪的问题。
My database has a table with name Ticket
and has 49300 records. 我的数据库有一个名为
Ticket
的表,并有49300条记录。 This table has multiple other tables linked. 该表具有多个其他链接的表。 Entity Framework diagram is available at: http://i.imgur.com/u4gKVFI.png
实体框架图可从以下网站获得: http : //i.imgur.com/u4gKVFI.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. 我的EF数据上下文可作为类的静态变量全局使用。 When I fire following code, it takes 12-15 seconds to load data (only talking about
.ToList()
method). 当我执行以下代码时, 加载数据需要12到15秒的时间(仅谈论
.ToList()
方法)。 and bind with DataGridView. 并与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; }
If you really need to bind that many records to the DataGridView, you should use Virtual Mode . 如果确实需要将那么多记录绑定到DataGridView,则应该使用Virtual Mode 。
Quote from msdn Implementing Virtual Mode with Just-In-Time Data Loading in the Windows Forms DataGridView Control : 引用msdn 在Windows窗体DataGridView控件中通过实时数据加载实现虚拟模式 :
One reason to implement virtual mode in the DataGridView control is to retrieve data only as it is needed.
在DataGridView控件中实现虚拟模式的原因之一是仅在需要时才检索数据。 This is called just-in-time data loading .
这称为即时数据加载 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.