.net - How to filter parent list<> when we apply condition on child list? -
how filter parent list<> when apply status on kid list ?
public class vendorentities { public int vendorid { get; set; } public string vendorname { get; set; } public list<itementities> itemdealdetails { get; set; } } public class itementities { public int itemid { get; set; } public string itemname { get; set; } public int tenantid { get; set; } } list<vendorentities> objvenderlist = new list<vendorentities>(); objvenderlist = objvendorbl.getvendorname(); var rlist = (from in objvenderlist b in a.itemdealdetails b.itemname.contains("computer") orderby a.vendorname descending select a).tolist().distinct();
now want search vendor itemname
contains computer
store in kid list itementities
. how can this? please give me suggestions.
you can utilize enumerable.any
:
var rlist = objvenderlist .where(v => v.itemdealdetails.any(d => d.itemname.contains("computer"))) .orderbydescending(v => v.vendorname) .tolist();
note i've omitted distinct
since removes duplicate references anyway until haven't implemented iequatable<t>
or overridden equals
+ gethashcode
.
here same in query syntax:
var filteredbyitemnamecomputer = vendor in objvenderlist vendor.itemdealdetails.any(d => d.itemname.contains("computer")) orderby vendor.vendorname descending select vendor; var rlist=filteredbyitemnamecomputer.tolist();
.net linq list
No comments:
Post a Comment