无法将 LINQ 查询变量转换为 DataTable
我有以下代码:
var _permiso = from P in _db.clsPermiso
select P;
var _pagina = from P in _db.clsPagina.AsEnumerable()
select P;
var _perfil = from P in _db.clsPerfil
select P;
IEnumerable<DataRow> query = from permiso in _permiso.AsEnumerable()
join perfil in _perfil.AsEnumerable()
on permiso.ID equals perfil.ID
join pagina in _pagina.AsEnumerable()
on permiso.ID equals pagina.ID
where (permiso.Acceso == true) && (permiso.Perfil.ID == Convert.ToInt32(strIDPerfil))
select pagina;
我一直在 MSDN 页面上收集一些信息,它告诉我使用 IEnumerable
,然后将该 query
变量分配给像这样的 DataTable var:
DataTable _dtResult = query.CopyToDataTable();
但我在 select pagina
语句中收到错误:
不能隐式转换类型 'System.Collections.Generic.IEnumerable
谢谢您的建议
I have the following code:
var _permiso = from P in _db.clsPermiso
select P;
var _pagina = from P in _db.clsPagina.AsEnumerable()
select P;
var _perfil = from P in _db.clsPerfil
select P;
IEnumerable<DataRow> query = from permiso in _permiso.AsEnumerable()
join perfil in _perfil.AsEnumerable()
on permiso.ID equals perfil.ID
join pagina in _pagina.AsEnumerable()
on permiso.ID equals pagina.ID
where (permiso.Acceso == true) && (permiso.Perfil.ID == Convert.ToInt32(strIDPerfil))
select pagina;
I've been gathering some info on the MSDN page, and it tells me to use IEnumerable<DataRow>
and then, asign that query
variable into a DataTable var like this:
DataTable _dtResult = query.CopyToDataTable();
But im getting the error at the select pagina
statement:
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<MyApp.Models.clsPagina>' to 'System.Collections.Generic.IEnumerable<System.Data.DataRow>'. An explicit conversion exists (are you missing a cast?)
Thx in advice
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
转换枚举不一定使用基类型使用的隐式转换。您可能必须在 LINQ 查询中将结果“pagina”显式转换为 DataRow。
我只是猜测,不知道您的类/类型定义,但我相信您希望 LINQ 查询的最后一行是:
您希望结果更原始是否有特定原因?
Converting enumerables does not necessarily use the implicit conversions that the base types use. You will likely have to explicitly cast the result "pagina" as a DataRow in your LINQ query.
Not knowing your class/type definitions, I'm only guessing, but I believe you want your last line of your LINQ query to be:
Is there a specific reason you want the result as more primitive?