filtering in linq using where clause

A frequent database operation is the filtering operation and is applied when retrieving data from a data store. When we apply a filter condition data which satisfies the filter condition is returned. In other words, the filter specifies the data to be filtered in the result set.

The where clause is commonly used in a filter expression and describes which elements have to be returned. Logical operators like AND and OR are used in the filter expression along with the where clause. The Where clause is frequently used with the group clause. The group clause is placed before the where clause when we want the source data to be grouped before applying the filter condition.

Listed below are two queries which use the Where clause. The first one is a Linq to object query and the second one is a Linq to Sql query.

Query1: Linq to object query

This query filters the data in the collection based on the condition � length of string should be greater than 5.

List continents = new List(); 	
continents.Add("Asia");                  
continents.Add("Africa");                   
continents.Add("NorthAmerica");                
continents.Add("Australia");   
IEnumerable query = from c in continents
               			where c.Length > 5 
						orderby c select c;

Query2: Linq to Sql query

This query filters the data in the table based on the condition � record having a CustomerId equal to 1.

SalesDBDataContext dataContext = new SalesDBDataContext();
        Customer custQuery =
        from custs in dataContext.Customers
        where custs.CustomerId == 1
        select custs;