Apress pro LINQ Language Integrated Query in C# 2008 phần 1 docx

56 469 0
Apress pro LINQ Language Integrated Query in C# 2008 phần 1 docx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

this print for content only—size & color not accurate spine = 1.176" 624 page count Books for professionals By professionals ® Pro LINQ: Language Integrated Query in C# 2008 Dear Reader, Pro LINQ: Language Integrated Query in C# 2008 is all about code. Literally, this book starts with code and ends with code. In writing this book, it has been my desire to create a treasury of meaningful LINQ examples. Rather than show you a single, simplest case example, I’ve strived to fill in the whole picture and demonstrate the breadth of LINQ operators and prototypes that are available to you. With this information, you will be able to put LINQ to use as it was intended and reap the maximum rewards for your investment. Throughout this book, it is my aim to give you the information that actually matters in a form that you can use. So, rather than obscure the relevant LINQ principles by focusing on a complex demonstration application you can’t put to practical use, Pro LINQ cuts right to the chase of each LINQ operator, method, or class. However, where complexity is necessary to truly demonstrate an issue, the examples are right there in the thick of it. For example, code samples dem- onstrating how to handle concurrency conflicts actually create concurrency conflicts, so you can step through the code and see them unfold. This book is for anyone with an elementary understanding of C# who wants to understand LINQ and LINQ-relevant C# 3.0 language features. You need not be up on all the latest C# 2.0 or 3.0 features to understand Pro LINQ. When a deeper knowledge of an advanced language feature is necessary, I begin from the ground up to make sure everyone is well equipped for the discussion. Joseph C. Rattz, Jr. US $44.99 Shelve in Programming/C# User level: Intermediate–Advanced Rattz LINQ The eXperT’s Voice ® in .neT Pro LINQ Language Integrated Query in C# 2008 cyan MaGenTa yelloW Black panTone 123 c Joseph C. Rattz, Jr. Companion eBook Available THE APRESS ROADMAP Silverlight and .NET 3.5 Recipes in C# 2008 Pro C# 2008 and the .NET 3.5 Platform Pro WPF in C# 2008, 2e Illustrated C# 2008 Accelerated C# 2008 Pro .NET 3.5 Scalable Application Design Expert Service-Oriented Architecture, 3e Beginning ASP.NET 3.5 Data Access, 2e Beginning C# 2008 Databases Beginning C# 2008 Pro LINQ: Language Integrated Query in C# 2008 www.apress.com SOURCE CODE ONLINE Companion eBook See last page for details on $10 eBook version ISBN-13: 978-1-59059-789-7 ISBN-10: 1-59059-789-3 9 781590 597897 5 4 4 9 9 Learn to use the power of Microsoft’s ground-breaking new technology. Language Integrated Query in C# 2008 Pro netbooks.wordpress.com Codered @ Updatesofts.com [...]... 2007 2:29 PM PART 1 ■■■ Pro LINQ: Language Integrated Query in C# 2008 Rattz_789-3C 01. fm Page 2 Tuesday, October 2, 2007 2:29 PM Rattz_789-3C 01. fm Page 3 Tuesday, October 2, 2007 2:29 PM CHAPTER 1 ■■■ Hello LINQ Listing 1- 1 Hello LINQ using System; using System .Linq; string[] greetings = {"hello world", "hello LINQ" , "hello Apress" }; var items = from s in greetings where s.EndsWith( "LINQ" ) select s;... construct the XML data into an object named books that I can programmatically interact with Listing 1- 2 A Simple XML Query Using LINQ to XML using System; using System .Linq; using System.Xml .Linq; XElement books = XElement.Parse( @" Pro LINQ: Language Integrated Query in C# 2008 Joe Rattz Pro WF: Windows Workflow in NET 3.0 Bruce... Query a SQL Server Database My next example shows how to use LINQ to SQL to query database2 tables In Listing 1- 3, I query the standard Microsoft Northwind sample database Listing 1- 3 A Simple Database Query Using LINQ to SQL using System; using System .Linq; using System.Data .Linq; using nwind; Northwind db = new Northwind(@"Data Source=.\SQLEXPRESS;Initial Catalog=Northwind"); var custs = from c in. .. of LINQ LINQ to SQL LINQ to SQL is the name given to the IQueryable API that allows LINQ queries to work with Microsoft’s SQL Server database This interface was previously known as DLinq in older prereleases of LINQ To take advantage of LINQ to SQL, you must have a reference to the System.Data .Linq. dll assembly in your project and have a using directive such as the following: using System.Data .Linq; ... Obtain LINQ Technically, there is no LINQ product to obtain LINQ is just the project code name for the query feature being added to C# 3.0 and the NET Framework 3.5, which will make their debut in the next version of Visual Studio, Visual Studio 2008 To get up-to-date information on LINQ and Visual Studio 2008, visit http://www.linqdev.com and http:/ /apress. com/book/bookDisplay.html?bID =10 2 41 LINQ. .. Apress 3 Rattz_789-3C 01. fm Page 4 Tuesday, October 2, 2007 2:29 PM 4 CHAPTER 1 ■ HELLO LINQ Query XML While the example in Listing 1- 1 is trivial, the example in Listing 1- 2 may begin to indicate the potential power that LINQ puts into the hands of the NET developer It displays the ease with which one can interact with and query Extensible Markup Language (XML) data utilizing the LINQ to XML API You should... added a using directive for the System.Xml .Linq namespace Running the previous code by pressing Ctrl+F5 outputs the following data to the console window: Pro LINQ: Language Integrated Query in C# 2008 Did you notice how I parsed the XML data into an object of type XElement? Nowhere did I create an XmlDocument Among the benefits of LINQ to XML are the extensions made to the XML API Now instead of being XmlDocument-centric... 212 Creating Names with XName 213 Creating Namespaces with XNamespace 214 Creating Nodes with XNode 214 Creating Processing Instructions with XProcessingInstruction 214 Creating Streaming Elements with XStreamingElement 216 Creating Text with XText 217 Creating CData... 5/22 /19 97 12 :00:00 AM - 10 545 - Lazy K Kountry Store … 4 /17 /19 98 12 :00:00 AM - 11 032 - White Clover Markets 5 /1/ 1998 12 :00:00 AM - 11 066 - White Clover Markets Use the Cast or OfType Operators for Legacy Collections You will find that the majority of LINQ s Standard Query Operators can only be called on collections implementing the IEnumerable interface None of the legacy C# collections—those in the... features of C# are allowing all of this? The answer is Microsoft’s Language Integrated Query, otherwise known as LINQ 1 Most noticeably, the order is inverted from typical SQL Additionally, there is the added “s in portion of the query that provides a reference to the set of elements contained in the source, which in this case is the array of strings “hello world,” “hello LINQ, ” and “hello Apress 3 . Service-Oriented Architecture, 3e Beginning ASP.NET 3.5 Data Access, 2e Beginning C# 2008 Databases Beginning C# 2008 Pro LINQ: Language Integrated Query in C# 2008 www .apress. com SOURCE CODE ONLINE Companion eBook . print for content only—size & color not accurate spine = 1. 176" 624 page count Books for professionals By professionals ® Pro LINQ: Language Integrated Query in C# 2008 Dear Reader, Pro. technology. Language Integrated Query in C# 2008 Pro netbooks.wordpress.com Codered @ Updatesofts.com

Ngày đăng: 06/08/2014, 08:22

Từ khóa liên quan

Mục lục

  • Prelims

  • Contents at a Glance

  • Contents

  • About the Author

  • About the Technical Reviewer

  • Acknowledgments

  • Hello LINQ

    • A Paradigm Shift

      • Query XML

      • Query a SQL Server Database

      • Introduction

        • LINQ Is About Data Queries

        • Components

          • LINQ to Objects

          • LINQ to XML

          • LINQ to DataSet

          • LINQ to SQL

          • LINQ to Entities

          • How to Obtain LINQ

          • LINQ Is Not Just for Queries

          • Tips to Get You Started

            • Use the var Keyword When Confused

            • Use the Cast or OfType Operators for Legacy Collections

            • Prefer the OfType Operator to the Cast Operator

            • Don’t Assume a Query Is Bug-Free

Tài liệu cùng người dùng

Tài liệu liên quan