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; }
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
Post a Comment