sjo*_*285 0 c# linq asp.net-mvc performance
有没有办法有这个相同的想法,即在这些值上设置一天,而不会对搜索时间造成巨大影响?没有这段代码,它会在一秒钟内加载一个新页面.添加后,页面加载之间的时间为6-7秒.
//incidents is an IQueryable
//Set date backwards one day if incident is entered during third shift after midnight
for (var x = 0; x < incidents.Count(); x++){
DateTime createdDate = incidents.ToList().ElementAt(x).DateCreated;
TimeSpan createdTime = createdDate.TimeOfDay;
if (createdTime > startTime && createdTime < endTime){
incidents.Skip(x).First().DateCreated = new DateTime(2019,01,01);
}
}
Run Code Online (Sandbox Code Playgroud)
既然incidents是IQueryable,您正在执行数据库调用2x+1时间.一次Count,每次事件加一次ToList,一次.Skip(x).First
您可以尝试ToList() 在循环之前调用并处理水合列表以查看性能是否有所改善.
| 归档时间: |
|
| 查看次数: |
62 次 |
| 最近记录: |