c# - Entity Framework : does IQueryable or IEnumerable get all the results at the first place?

标签 c# entity-framework linq-to-sql entity-framework-4 linq-to-entities

我了解到 IQueryable 或 IEnumerable 数据类型不会首先返回结果,只在需要时才返回结果。但是,当我在 watch inspector 中打开该对象时,我看到所有对象都在那里。

我的代码有什么问题吗?还是因为我在 watch 上调用它才显示出来?

[当我在监视对话框中查看 pendings 对象时,我看到了所有列表项,但它不应该首先加载。我的接近有什么问题还是只是显示因为我在 watch 上打电话。]

 public IQueryable<PurchasePendingView> PurchasePendings() {
            var pendings = db.PurchasePendingViews
                             .Where(m => m.AccountStatusID != StructAccountStatus.Succeed); // when I view it in the watch dialougebox I saw all the list items but it shouldn't load at the first place. Is there anything wrong in my approaching or is it just showing because I had call it on the watch. 
            if (ApplicationEnvironment.DEBUGGING) {
                return pendings;
            } else if (IsMobileAccount()) {
                var showroom = db.ShowRooms.FirstOrDefault(m=> m.MemberID == employee.MemberID);
                if (showroom != null) {
                    return pendings.Where(m => m.ShowRoomID == showroom.ShowRoomID);
                } else {
                    return pendings.Where(m => m.CountryDivisionID == employee.CountryDivisionID);
                }
            } else { 
                //normal salary employee can see every detail
                return pendings;
            }
        }

注意:目前我的延迟加载已关闭。

最佳答案

集合会在您第一次遍历结果时进行评估。

由于您在 watch inspector 中迭代结果,因此会对其进行评估。

关于c# - Entity Framework : does IQueryable or IEnumerable get all the results at the first place?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12802226/

相关文章:

c# - System.threading.timer 在 Windows 服务中不工作

c# - Linq 到 NHibernate : 'System.Linq.EnumerableQuery` 1[Entity]' cannot be converted

entity-framework - 多个 DbContext 类使用相同的连接字符串?

c# - 谁能解释一下以下两个查询的区别?

c# - 当我的代码不存在时,我如何让我的代码创建一个 sqlite 数据库?

c# - 使用 UNION 时无法在 C# 中编辑 Datagridview

c# - 如何确定我的 EF 6 数据库初始化程序是否会运行?

entity-framework - Entity Framework 中多列的唯一键约束

linq-to-sql - 解决 LinqToSQls "queries with local collections are not supported"异常

c# - 使用linq通过两个表中的多列进行简单连接的问题