我有这个 LINQ to Entity 查询,它可以获取大约 5000 条 Plus 记录。我注意到,返回的记录越高,执行查询和返回结果所需的时间就越多。
lstUserAssignments = context.UserAssessments.Where(a=>a.UserID == UserID && a.CourseID == ClassID && a.ProductID == a.ProductID && a.AppID == ApplicationID && a.IsDeleted == false && a.Score_Percentage >= 0).Select(a=> new UserAssessmentEntity()
{
ApplicationID = a.AppID,
AttemptNo = a.AttemptNo,
CourseID = a.CourseID,
Score_Percentage = (float)(a.Score_Percentage != null ? a.Score_Percentage : 0),
Status = a.Status,
UserAssessmentID = a.UserAssessmentID,
UserID = a.UserID,
UserScore = a.User_Score,
CreatedDateTime = a.CreatedDateTime,
ModifiedDateTime = a.ModifiedDateTime,
TimeSpent=a.UserAssessmentDetails.Sum(i=>i.TimeSpent??0),
InstructorFeedbackText = a.UserAssessmentDetails.FirstOrDefault()!=null?a.UserAssessmentDetails.FirstOrDefault().InstructorFeedbackText:string.Empty
}).ToList();
使查询简单。有 UserAssessment 和 UserAssessmentDetails 表。第一个是父母,后一个是孩子。查询中有一些性能问题,我觉得它在计算 TimeSpent 和 InstructorFeedback。谁能指出我的问题。