c# - list.AddRange Cannot implicitly convert type 'void' -
namespace subscriptionwebsite.placeholders { public class treedata { public int id { get; set; } public int? parentlocationid { get; set; } public string name { get; set; } public int? locationlevel { get; set; } public string participation { get; set; } } } namespace subscriptionwebsite.managers { public class treedatamanager { subscriptionwebsite.entities.acc_core_dbentities db = new subscriptionwebsite.entities.acc_core_dbentities(); public list<treedata> gettreedata() { list<treedata> location = db.frm_location.where(x => !x.removed && x.revision == 0).select(loc => new treedata { id = loc.id, parentlocationid = loc.parentlocationid, name = loc.frm_location_level.systemid.equals(5) ? loc.frm_location_address.firstordefault(c => !c.removed && c.revision == 0).street1 : loc.name, locationlevel = loc.frm_location_level.systemid, participation = loc.isactive ? "yes" : "no", }).tolist(); list<treedata> meters = db.frm_connection_meter.where(x => !x.removed && x.revision == 0).select(l => new treedata { locationlevel = 6, id = l.id, parentlocationid = l.frm_location.id, name = l.meternumber, participation = l.ismain ? "yes" : "no",// change isactive after db update }).tolist(); return location.addrange(meters)); } } }
if try put 2 lists of treedata
return location.addrange(meters));
i following error: cannot implicitly convert type 'void' system.collections.generic.list
i know return type of the.addrange void(null) how can put 2 list ?
list.addrange
doesn't return since modifies list directly:
location.addrange(meters); return location;
if don't want modify can use linq:
return location.concat(meters).tolist();
but wouldn't create other 2 lists, more efficient:
public list<treedata> gettreedata() { var locations = db.frm_location .where(x => !x.removed && x.revision == 0) .select(loc => new treedata { id = loc.id, parentlocationid = loc.parentlocationid, name = loc.frm_location_level.systemid.equals(5) ? loc.frm_location_address.firstordefault(c => !c.removed && c.revision == 0).street1 : loc.name, locationlevel = loc.frm_location_level.systemid, participation = loc.isactive ? "yes" : "no", }); var meters = db.frm_connection_meter .where(x => !x.removed && x.revision == 0) .select(l => new treedata { locationlevel = 6, id = l.id, parentlocationid = l.frm_location.id, name = l.meternumber, participation = l.ismain ? "yes" : "no",// change isactive after db update }); return locations.concat(meters).tolist(); }
Comments
Post a Comment