none
Multiple OR Statement rather than AND Statement RRS feed

  • Question

  • if (..)

    CodesQuery = CodesQuery.Where(x => x.Id == ServiceAdjustmentsClass.AdjustmentGroupCode || x.Id == ServiceAdjustmentsClass.AdjustmentReasonCode);

    else

    CodesQuery = CodesQuery.Where(x => x.Id == ServiceAdjustmentsClass.AdjustmentGroupCode || x.Id == ServiceAdjustmentsClass.AdjustmentReasonCode);

    End up with ANDs, how can I use link to dynamically generate ORs without using Contains?

     

    Fahd

    Thursday, July 15, 2010 8:42 PM

Answers

All replies

  • Hi Fahd,

    I can not find any differences between the code in "If" and "else" clauses, and I did not find any code using "Contains". Could you please explain your question a little ? Thanks.

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, July 20, 2010 9:52 AM
    Moderator
  • Alex I think he means the generated sql code, he want it to generate OR statements instead of AND without using Constains, I agree that he should elaborate better.

    Fahd, to be honest, to gain that kind of control the best way is to use sql instead of letting linq generate the code.  Please explain better what you want and why.

    Regards

    Tuesday, July 20, 2010 1:43 PM
  • Yes, both of you are right.

    I am looping through some records and I want to build an OR statement instead of AND. CodesQuery.Where generates AND sql statements; therefore, I would need to find another way of doing without using Contains but I don't think I have another choice. In Nhibernate, we use Disjunction class to take care of it.

    I am surprised it's not built-in to LinQ/.NET

     

    Fahd

    Tuesday, July 20, 2010 1:50 PM
  • There is something that you could try, haven't used it myself but...

    http://www.albahari.com/nutshell/predicatebuilder.aspx 

    It is a nifty extension to linq

    Regards

    Tuesday, July 20, 2010 2:22 PM
  • I think SQL is faster with ANDs than ORs, so it is just converting the ORs to ANDs using de Morgan's Laws.
    Wednesday, July 21, 2010 3:50 PM