Results 1 to 6 of 6

Thread: How to insert more than one condition in where method?

  1. #1
    Join Date
    Nov 2009
    Posts
    72

    How to insert more than one condition in where method?

    Hello friends,
    I have written following code, but there is one problem in it.
    Code:
    codebase.Methods.Where(a => a.Bodys.Scopess.Count > 5);
    I want to use "a=> predicate && b => predicate" in where method. I don't know how to use it. Can anyone tell me how to insert more than one condition in where method? Please help me.
    Thank you.

  2. #2
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to insert more than one condition in where method?

    Hey you have to separate that two condition to fix this problem. It means you have to separate these two condition into single on and then after using "&&" you have to combine these condition. You can do this in following way.
    Code:
    codebase.Methods.Where(a => (a.Bodys.Scopess.Counts > 5) && (a.Foos == "test"));

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to insert more than one condition in where method?

    You have to use two where method to fix this problem. It means you have to place that two condition in separate where condition to overcome this problem. If you don't know how to do this then use following code.
    Code:
    codebase.Methods.Where(a => a.Bodys.Scopess.Count > 6)
                    .Where(a => a.Foos == "testing this code");

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: How to insert more than one condition in where method?

    Hey you can not declare two delegates in the same where method but you can put both on same condition to do this. You can do this in one of the following way.
    Code:
    var results = codebase.Methods.Where(a => a.Bodys.Scopess.Counts > 5 && a.Bodys.Scopess.names == "" );
    or
    Code:
    var results = codebase.Methods.Where(a =>a.Bodys.Scopess.Counts > 5 )
            .where( b=> b.Bodys.Scopess.names == '' );
    or
    Code:
    var results = codebase.Methods.Where(a =>a.Bodys.Scopess.Counts > 5  )
    .Union( codebase.Methods.Where(b => b.Bodys.Scopess.names == ''  ) );

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to insert more than one condition in where method?

    In your code what is that "b" represent? There is no need to use "b" here. You can use easily do this using standard && condition. I have written following code for you. Just try to understand this.
    Code:
    codebase.Methods.Where(a => a.Bodys.Scopess.Counts > 6 && a.Bodys.SomethingElses < 14);

  6. #6
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How to insert more than one condition in where method?

    Hey it is very simple to use two condition in where methods. You can do this in following ways.
    Code:
    codebase.Methods.Where(a=> a.Bodys.Scopess.Counts > 6 && a.Bodys.Scopess.Counts < 10);
    In the above code I have just combine these two condition using "&&".

Similar Threads

  1. Method overriding versus method hiding in C#
    By ^MALARVIZHI^ in forum Software Development
    Replies: 4
    Last Post: 25-12-2010, 06:25 AM
  2. Is it possible to call destroy() method within init() Method?
    By Level8 in forum Software Development
    Replies: 3
    Last Post: 10-12-2009, 08:36 AM
  3. What is method overriding and method overloading in java
    By beelow in forum Software Development
    Replies: 3
    Last Post: 17-11-2009, 08:20 AM
  4. Java: How can I call one method in another method?
    By biohazard 76 in forum Software Development
    Replies: 3
    Last Post: 16-07-2009, 07:12 PM
  5. if Condition in HTML
    By Ettan in forum Software Development
    Replies: 1
    Last Post: 14-10-2008, 05:48 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,307,040.41558 seconds with 17 queries