c# - Skip all items after first one with same id -
assume have list<customobject> list.
customobject has next structure :
public class customobject { public int coid{get;set;} public list<subcustobj> sublist{get;set;} public datetime datepublish{get;set;} } public class subcustobj { public int id{get;set;} public region rregion{get;set;} } // region : it's important know has regionid if in list exists customobject's same coid in region need leave 1 element recent datepublish. in other words, 1 coid - 1 region. how can it?
//list it's list<customobject> var todelete = ist.selectmany(r => r.sublist.where(m => r.sublist.count() > 2) .select(rm => rm.rregion.regionid)); this code select ids of region repeated, todo next don't know.
some new idea : can group elements regionid , after select first element in group?
you can select pairs (region, customobject), order datepublish, group region, , pick first item each group:
var res = list .selectmany(c => c.sublist.select(s => new {custom = c, region = s.rregion})) .orderbydescending(p => p.custom.datepublish) .groupby(p => p.regionid) .select(g => g.first()); this gives pairs of customobject, region such regions not repeated (customobjects may repeated, though).
Comments
Post a Comment