我有以下属性:
Public ReadOnly Property AppointmentDate As Date?
Get
Dim _apt = _person.Appointments.OrderBy(Function(c) c.AppointmentDate).FirstOrDefault
If IsNothing(_apt) Then Return Nothing
Return _apt.AppointmentDate
End Get
End Property
当我对大量记录(大约1,000个)进行数据处理时,数据表大约需要30-40秒。如果我删除此属性,整个数据绑定需要1-2秒。
我已经尝试将其更改为:
Public ReadOnly Property AppointmentDate As Date?
Get
If _cxt.Appointments.Where(Function(p) p.LeadId = _person.Id).Count() = 0 Then Return Nothing
Dim _apt = _person.Appointments.OrderBy(Function(c) c.AppointmentDate).FirstOrDefault
Return _apt.AppointmentDate
End Get
End Property
认为通过执行计数会减少开销,但仍然一样慢。
有更好的方法吗?