python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
IEnumerable vs. IList

LINQ filtering Operators - where clause

The where clause is a filtering operator and used to filter a collections based on the some specific criteria and after that returns the values from collection based on your given criteria (returns those which are specified condition is true).

It is accepts a predicate as a parameter.

The where extension method has following two overloads,
1.      Func<TSource, bool>
2.      Func<TSource,  int, bool>

A single LINQ query may contain multiple where clauses and a single clause may contain multiple predicate sub expressions.

The multiple where extension methods are valid in a single LINQ query.

For example, Multiple where clauses query,

var query = base.Context.Carts.Where(x => x.EmailID == EmailID)
        .Where(x => x.IsDeleted == false) //APPLIED TO THE RESULT OF THE PREVIOUS.
        .OrderByDescending(x => x.CartID)
        .ToList();

        //OR

var query = base.Context.Carts
       .Where(x => x.EmailID == EmailID && x.IsDeleted == false)
       .OrderByDescending(x => x.CartID)
       .ToList();
        //OR

var query = from cart in Carts
     orderby cart.CartID descending,
cart.CartNumber descending
     select cart.Name;

        //OR

var query = from customer in Customers
          where customer.ID == 101
          where customer.ID == 103
          where customer.ID == 105
       select customer;


I hope it is helpful to you! Thank you!
ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions