c# - Cannot implicitly convert type from IOrderedQueryable<T> to List<T> -


i following error on seminariolista = line:

cannot implicitly convert type iorderedqueryable list

public list<seminario> listarseminariomodal() {     var seminariolista = new list<seminario>();     try     {         using (var ctx = new proyectocontext_())         {             seminariolista = ctx.seminario.where(x => x.modal == 1)             .orderby(x => x.orden);         }     }     catch (exception)     {         throw;     }     return seminariolista; } 

visual studio screenshot

probably defining as

ienumerable<seminario> seminariolista = null; 

and returning

return seminariolista.tolist(); 

will work.

but in general it's not idea, in opinion, return list object, unless explicitly need it. return ienumeralble, keep method signature general possible. so, best solution code, in opinion , without knowing requirement of application , rest of code:

public ienumerable<seminario> listarseminariomodal() {     ienumerable<seminario> seminariolista = null;     try     {         using (var ctx = new proyectocontext_())         {             seminariolista = ctx.seminario.where(x => x.modal == 1)             .orderby(x => x.orden);         }     }     catch (exception)     {         throw;     }     return seminariolista.toarray(); } 

note toarray() call @ end, hide linq stuff outside method body.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -