【问题标题】:EntityDataSource: TotalRowCount returns -1. What's that?EntityDataSource:TotalRowCount 返回 -1。那是什么?
【发布时间】:2010-03-02 21:18:03
【问题描述】:

我有一个带有 OnSelected 事件的 EntityDataSource(在完成查询后触发)。事件处理程序具有EntityDataSourceSelectedEventArgs e 类型的事件参数。查询运行良好且没有错误,IEnumerable e.Results 包含 1 个对象(我可以通过非空的 foreach 循环运行)但 e.TotalRowCount 返回 -1

有人知道这意味着什么以及TotalRowCount 实际表达的信息是什么吗?如果不使用TotalRowCount,如何确定选定对象的数量?

【问题讨论】:

    标签: asp.net entity-framework entitydatasource


    【解决方案1】:

    来自http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.entitydatasource.selected(VS.100).aspx

        The TotalRowCount property of the EntityDataSourceSelectedEventArgs 
    object shows the total number of objects in all pages, regardless of the 
    values passed by the data-bound control for paging. 
    
        TotalRowCount is only retrieved if the data-bound 
    control needs it, such as if paging is enabled.
    

    您的数据绑定控件是否使用分页?

    【讨论】:

    • 不,它不使用分页。好的,谢谢,这解释了为什么 TotalRowCount 没有分页是无用的。但是那我如何确定对象的数量呢?
    • 既然 e.Results 是一个 IEnumerable,那么 e.Results.Count() 怎么样?
    • e.Results 是一个 System.Collections.IEnumerable,它似乎没有 Count() 方法或属性 - 与 System.Collections.Generic.IEnumerable<T> 相比。
    • 尝试导入 Linq 命名空间并使用它的扩展方法。
    • System.Linq 和 System.Data.Linq 已经导入,但没有帮助。扩展方法似乎仅适用于 IEnumerable 的通用版本,但不适用于非通用版本。在查看了这里关于 IEnumerable 的各种其他讨论之后,我认为唯一的方法是真正遍历 IEnumerable 并计算对象。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-25
    • 2012-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多