How to write a foreach in my Where for OR || RRS feed

  • Question

  • User1991482975 posted


    i have a table called Advertises

    and i need to shwo only the records which contains in my UserPartners Table the same UserId and PArtnerId

    var partneradvertises = db.PartnerAdvertises.Include(s => s.ParentPartner.ListPartnerUser) as IQueryable<PartnerAdvertise>;

    i try this but does not work

     //I check each user active for the partner
                var userforpartner = db.PartnerUsers.Where(r => r.PartnerUserActive.Equals(true) && r.PartnerUserDelete.Equals(false) && r.ParentPartnerForUser.PartnerVisible.Equals(true) && r.ParentPartnerForUser.PartnerDelete.Equals(false) && r.UserId.ToLower() == str.ToLower()).OrderByDescending(r => r.PartnerUserDate).ToList();
                foreach (var itememail in userforpartner)
                partneradvertises = partneradvertises.Where(r => r.UserId == str || r.PartnerId == itememail.PartnerId );

    how can i make a foreach in my table and gnerate an OR || statement with the list of USERSID?

    Tuesday, December 22, 2020 2:29 PM

All replies

  • User1686398519 posted

    Hi grafic.web, 

    i try this but does not work

    Do you mean you did not get the correct result?

    i make a foreach in my table and gnerate an OR || statement with the list of USERSID?

    I don't quite understand what you mean here. Can you describe it in detail? Or you can provide some necessary code and the error you encountered.

    Best Regards,


    Wednesday, December 23, 2020 9:12 AM
  • User1991482975 posted

    yes it is not really clear..

    i was wondering if i can to a foreac inside my Where. statement

    and polulate my OR string

    partneradvertises = partneradvertises.Where(r => r.PartnerId == itemforeach.PartnerId || r.PartnerId == itemforeach.PartnerId || r.PartnerId == itemforeach.PartnerId );


    Wednesday, December 23, 2020 11:11 AM
  • User-474980206 posted

    linq is set operations, there i no need for a foreach operator. you use the where clause to filter. 

    Wednesday, December 23, 2020 4:30 PM