Unable to step into or break in method called inside Linq query/expression

假如想象 提交于 2019-12-06 06:48:59

You need to evaluate the expression.

Just call ToArray(), ToList(), Count(), or any other method or extension on IEnumerable<T> which forces evaluation.

The result of Select is evaluated using deferred execution, so nothing happens with GetTableDataRow until the query is used.


More explicitly, you can see this by expanding out what Select does:

IEnumerable<TagBuilder> theOutcome = resultSet.Select(r => GetTableDataRow(null));

is equivalent to

IEnumerable<TagBuilder> theOutcome = getRows(resultSet);

where getRows is:

IEnumerable<TagBuilder> getRows(IEnumerable<IPagedList> source)
{
    foreach ( IPagedListitem in source )
        yield return GetTableDataRow(null);
}

Because GetTableDataRow is yield returned, it's not evaluated until the evaluation is forced (e.g. by ToArray(), etc.).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!