Language Integrated Query (LINQ, pronounced “link”) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages. The main difference between SQL and LINQ is that the “from” keyword comes before the “select” keyword because we must first define the object we want to operate on. The “select” clause tells the compiler what we wish to extract in this query.
List initialization:
List<Book> ListOfBooks = new List<Book>() { new Book {name = "DaVinci Code" , owner = "Alex" , date = 2002}, new Book {name = "Angels and Demons", owner = "Jeff" , date = 2005}, new Book {name = "The Last Mughal", owner = "Danny", date = 2001}, };
LINQ query:
IEnumerable<Book> QueryResult = from Book in ListOfBooks select Book;
When we query things from objects (LINQ to Objects) our queries always return an “IEnumrable
foreach(Book bk in QueryResult) Console.WriteLine(bk.name);