Cant convert LINQ Query var to DataTable
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
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:
select (DataRow)pagina;
Is there a specific reason you want the result as more primitive?
精彩评论