2. Agenda What is LINQ? Why LINQ? LINQ with Object LINQ with XML LINQ with SQL Demo Q & A
3. What is LINQ? Stands for Language INtegrated Query. It is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages. It follows query expression rule.
4. Why? It provides consistent model for working with data across various kinds of data sources and formats, such as, Object, XML, Dataset, SQL, Entity with short and effective syntax. Improve performance.
7. LINQto Object The LINQ to Objects provider is used for querying in-memory collections, using the local query execution engine of LINQ. Example: string[] greetings = { "Hello world", "Hello LINQ", "Hello Apress"}; var items = from s in greetings where s.EndsWith("LINQ") select s; foreach (var item in items) txtResult.Text += item + ""; Result => Hello LINQ
8. LINQto XML The LINQ to XML provider converts an XML document to a collection of XElement objects, which are then queried against using the local execution engine that is provided as a part of the implementation of the standard query operator. Example: var titles = from book in books.Elements("book") where (string)book.Element("author") == "Steve Nolle" select book.Element("title"); foreach (var title in titles) txtResult.Text = title.Value; Result => Software Engineering
9. LINQto SQL The LINQ to SQL provider allows LINQ to be used to query SQL Server databases, including SQL Server Compact databases. Example: DataClasses1DataContext dc1 = new DataClasses1DataContext(); var hotel = from h in dc1.tbl_Hotels where h.city == "London" select h.hotelName; foreach (string h in hotel) txtResult.Text += h + "";
10. LINQto SQL DEMO The LINQ to SQL provider allows LINQ to be used to query SQL Server databases, including SQL Server Compact databases. Example: DataClasses1DataContext dc1 = new DataClasses1DataContext(); var hotel = from h in dc1.tbl_Hotels where h.city == "London" select h.hotelName; foreach (string h in hotel) txtResult.Text += h + "";
11. References “LINQ Quickly“ - N Satheesh Kumar “Pro LINQ in C# 2008” - Joseph C. Rattz, Jr. http://en.wikipedia.org/wiki/Language_Integrated_Query