【发布时间】:2012-08-06 08:44:34
【问题描述】:
性能是否会因where 子句在 linq 表达式中的位置而有所不同?
看看下面的代码:
dbContext.AnEntity.Include("AnotherEntity").Where(e => e.ID == id).ToList();
dbContext.AnEntity.Where(e => e.ID == id).Include("AnotherEntity").ToList();
这两个表达式的执行计划是相同还是不同?
【问题讨论】:
-
你确定你的代码真的编译了吗?在
ObjectQuery<T>实例上调用Include,但Where(some lambda expression here)方法返回IQueryable<T>。我认为您实际上无法选择放置Include的位置。
标签: .net performance linq