Jaa*_*nus 2 .net c# linq entity-framework ef-code-first
我正在使用ASP NET MVC
4.5和EF6
代码优先迁移.
我有这个代码,大约需要6秒钟.
var filtered = _repository.Requests.Where(r => some conditions); // this is fast, conditions match only 8 items
var list = filtered.ToList(); // this takes 6 seconds, has 8 items inside
Run Code Online (Sandbox Code Playgroud)
我认为这是因为关系,它必须在内存中构建它们,但事实并非如此,因为即使我返回0字段,它仍然很慢.
var filtered = _repository.Requests.Where(r => some conditions).Select(e => new {}); // this is fast, conditions match only 8 items
var list = filtered.ToList(); // this takes still around 5-6 seconds, has 8 items inside
Run Code Online (Sandbox Code Playgroud)
现在请求表非常复杂,关系很多并且有大约16k项.另一方面,筛选后的列表应该只包含8个项目的代理.
为什么ToList()
方法这么慢?我实际上认为问题不在ToList()方法中,但可能是EF问题,或者设计问题不好.
有没有经历过这样的事情?
编辑:
这些是条件:
_repository.Requests.Where(r => ids.Any(a => a == r.Student.Id) && r.StartDate <= cycle.EndDate && r.EndDate >= cycle.StartDate)
Run Code Online (Sandbox Code Playgroud)
所以基本上,我可以检查Student
id是否在我的id列表中并检查日期是否匹配.
归档时间: |
|
查看次数: |
6514 次 |
最近记录: |