7/6/16

Linq Queries

           //1............Select Products
           // var products = from product in ProductList select product.Name;
           // var products = ProductList.Select(a => new Product { Name = a.Name, Code = a.Code }).ToList();



            //2............Exclude duplicates get Distinct.
           //   var products = ProductList.Select(p => p.Name).Distinct();
            ////var products = from product in ProductList
            ////               select product.Name.Distinct();

            //3.............where condition
            //var products = from product in ProductList
            //               where product.Name == "apple"
            //               select product.Name;

            //checks existence of a keyword
List temp = (List)from u in ProductList
                                   where u.Name.Contains("apple")
                                   select u;
//check records that start with the keyword
List temp = (List)from u in ProductList
                                   where u.Name.StartsWith("apple")
                                   select u;

//check record that end with the keyword
List temp = (List)from u in ProductList
                                   where u.Name.EndsWith("apple")
                                   select u;

1 comment:

Chris Walsh said...

i like this post, we visit again for more updates , thanks for sharing this article.
cheap artificial grass