LINQ在获取数据之前甚至变慢了?

时间:2017-09-26 16:18:04

标签: entity-framework linq

我有以下查询:

var sw = new Stopwatch();
sw.Start();

var model = new StatusModel();

IQueryable<StatusView> statusViewResult = db.StatusViewList;         

statusViewResult = statusViewResult.Where(p =>
   (query.ClustersSelected.Count == 0 || query.ClustersSelected.Contains(p.Cluster)) &&
   (query.ParkNamesSelected.Count == 0 || query.ParkNamesSelected.Contains(p.ParkName)) &&
   (query.TurbineNumbersSelected.Count == 0 || query.TurbineNumbersSelected.Contains(p.TurbineNumber)) &&
   (query.ModelNamesSelected.Count == 0 || query.ModelNamesSelected.Contains(p.ModelName)) &&
   (query.AlarmLevelSelected.Count == 0 || query.AlarmLevelSelected.Contains(p.AlarmLevel)) &&
   (query.ParametersSelected.Count == 0 || query.ParametersSelected.Contains(p.Parameter)) &&
   (query.TurbineTypesSelected.Count == 0 || query.TurbineTypesSelected.Contains(p.TurbineType)));

sw.Stop();

var d = sw.Elapsed.TotalMilliseconds;

所以我没有做任何ToList()因此我现在不应该查询数据库。但是我只需要大约2秒来构建这个查询 - 我在这里错过了什么或者这是预期的吗?

0 个答案:

没有答案