Linq DataTable 和 Take 方法
我从数据表中使用 Linq:
var query = dt.AsEnumerable();
query = dt.AsEnumerable().Where(log => log.Field<byte>("Day") == day).Take(10);
以下错误:
无法隐式转换类型
'System.Collections.Generic.IEnumerable
到' 'System.Data.EnumerableRowCollection
。一个 存在显式转换(您是否缺少强制转换?)'
我尝试过 take(10) - 请您提供建议吗?
I have the following use of Linq from a datatable:
var query = dt.AsEnumerable();
query = dt.AsEnumerable().Where(log => log.Field<byte>("Day") == day).Take(10);
The following error:
Cannot implicitly convert type
'System.Collections.Generic.IEnumerable<System.Data.DataRow>'
to'System.Data.EnumerableRowCollection<System.Data.DataRow>'
. An
explicit conversion exists (are you missing a cast?)
I have tried take(10) - Please can you advise?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误本身是否肯定指向该行?如果您尝试过,我希望您能得到这一点:
在这种情况下,您可以通过将
query
的类型显式更改为IEnumerable
来修复它。(如果这不是问题所在,请给我们更多背景信息。一个简短但完整的方法来演示当前的问题会有所帮助。)
Does the error definitely point to that line, on its own? I'd expect you to get that if you tried:
in which case you could fix it by changing the type of
query
to be explicitlyIEnumerable<DataRow>
.(If that's not the problem, please give us more context. A short but complete method demonstrating just the problem at hand would help.)