Filter a list<object> by another list<object2> C# LINQ -


consider following lists:

class user {    public int id {get; set;}    public string name {get; set;}    public bool selected {get; set;}  }  class coupon {    public string username {get; set;}    public string coupontype {get; set;}    public string code {get; set;} }  list<user> luser = new list<user>(); list<coupon> lcoupon = new list<coupon>(); 

how possible (with linq) filter lcoupon luser values remain lcoupon.username field present in luser.name , luser.selected being true?

pseudo code:

lcoupon = lcoupon.where (w => luser.name == w.name , luser.selected == true).tolist(); 

you use linq any method on luser list, in:

var coupons = lcoupon     .where(c => luser.any(u => u.selected && u.name == c.username))     .tolist(); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -