【发布时间】:2011-12-21 12:34:48
【问题描述】:
我正在调用存储过程:
ObjectResult<ComplexType1> result = context.ListSomething(model.SelectedDatabase);
ViewBag.WebGrid = new WebGrid(source: result, rowsPerPage: int.MaxValue, canSort: false, canPage: false);
但是,当将 result 作为源传递给 WebGrid 时,我会收到:
System.InvalidOperationException:查询的结果不能 列举了不止一次。
我有点惊讶,因为 ObjectResult 实现了 IEnumerable(不是 IQueryable)。该异常背后的背景是什么以及为什么我必须调用 ToList() 方法:
var result = context.ListSomething(model.SelectedDatabase).ToList();
ViewBag.WebGrid = new WebGrid(source: result, rowsPerPage: int.MaxValue, canSort: false, canPage: false);
让它工作?您能否向我提供一些解释它的文档(例如来自Programming Entity Framework, 2nd Edition,因为我现在正在阅读它,但到目前为止我不记得有任何可以解释该机制的东西)。
谢谢, 帕维尔
【问题讨论】:
标签: linq entity-framework entity-framework-4 linq-to-entities