c# - How to use a lambda expression to return Collection -


given below error throwing type casting error

public collection<assignedreadingscheduledto> getassignedreadingschedulelist(int substationid, datetime getlastsyncdate, out string errormessage) {     assignedreadingscheduledto filter = new assignedreadingscheduledto();     collection<assignedreadingscheduledto> colasgnreadschedullist = null;     messageserviceclass messageservice = new messageserviceclass();     exceptioncodedto errormessagecode = null; errormessage = string.empty;     assignedreadingschedule_ida daasgnreadingschedulelist = (new assignedreadingscheduleda()).createdbobject();     try     {         filter.localcntrid = substationid;         filter.stationtype = 2;         colasgnreadschedullist = new collection<assignedreadingscheduledto>();         colasgnreadschedullist = daasgnreadingschedulelist.getassignedreadingschedulelist(0, int32.maxvalue, filter, out errormessagecode).where(x=>x.updateon >= getlastsyncdate) collection<assignedreadingscheduledto>;     }     catch (exception ex)     {         errormessagecode.referencenumber = messageservice.getexceptionrefnumber(ex);     }     return colasgnreadschedullist; } 

you can't directly create collection<t> standard linq methods. concrete types* build-in linq methods can create list<t> (via tolist) , array instances (via toarray). here's options:

  • create own extension method tocollection create collection<t> (or find third-party library has such method)

  • loop through results , add each item collection.

  • create list<t> , use collection<t> constructor takes ilist<t>

  • change return type icollection<t> (or ilist<t> or ienumerable<t>)


*i'm not counting projections or transformations todictionary , todatatable


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -