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
createcollection<t>
(or find third-party library has such method)loop through results , add each item collection.
create
list<t>
, usecollection<t>
constructor takesilist<t>
change return type
icollection<t>
(orilist<t>
orienumerable<t>
)
*i'm not counting projections or transformations
todictionary
, todatatable
Comments
Post a Comment