Thursday, September 16, 2010

Data LINQ examples

To use LINQ (Language Integrated Query) you just need to have the following 2 namespace reference
using System.Collections.Generic;
using System.Linq;


// using where clasue within the collection.
List allCities = Common.GetAllCities().Where(c => c.DewPoint> 1).ToList() ;

// using where clasue & some property contain value search.
List allCities1 = Common.GetAllCities().Where(c => c.StationName.Contains("a")).ToList() ;

// pick the default value collection
Climate climate = Common.GetAllCities().SingleOrDefault();

// pick the First/default value collection
Climate climate1 = Common.GetAllCities().FirstOrDefault();

// sort the list
Common.GetAllCities().Sort();

No comments:

ETG Consultancy

Web Designing Development Analysis & Promotion
Asp.Net 2.0 SQL WWF WCF SEO Marketing Ajax JQuery NHibernate MVC