1. Trang chủ
  2. » Công Nghệ Thông Tin

Pro LINQ Language Integrated Query in C Sharp 2008 docx

624 7,5K 0

Đ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

Thông tin cơ bản

Định dạng
Số trang 624
Dung lượng 9,77 MB

Nội dung

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 [...]... Rattz_789- 3C0 1.fm Page 10 Tuesday, October 2, 2007 2:29 PM 10 CHAPTER 1 ■ HELLO LINQ namespace LINQDev.Common { public class Contact { public int Id; public string Name; public static void PublishContacts(Contact[] contacts) { // This publish method just writes them to the console window foreach(Contact c in contacts) Console.WriteLine("Contact Id: {0} Contact: {1}", c. Id, c. Name); } } } As you can see,... PublishContacts method LINQ makes it easy, as shown in Listing 1-6 Listing 1-6 Calling the Common Code ArrayList alEmployees = LINQDev.HR.Employee.GetEmployees(); LINQDev.Common.Contact[] contacts = alEmployees Cast() Select(e => new LINQDev.Common.Contact { Id = e.id, Name = string.Format("{0} {1}", e.firstName, e.lastName) }) ToArray(); LINQDev.Common.Contact.PublishContacts(contacts);... 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 db.Customers where c. City == "Rio de Janeiro" select c; foreach (var cust... 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; LINQ to Entities LINQ to Entities is an alternative LINQ API that is used to interface with a database It decouples the entity object model from the physical database by injecting... his challenge, I learned that I can be Rattz_789- 3C0 1.fm Page 1 Tuesday, October 2, 2007 2:29 PM PART 1 ■■■ Pro LINQ: Language Integrated Query in C# 2008 Rattz_789- 3C0 1.fm Page 2 Tuesday, October 2, 2007 2:29 PM Rattz_789- 3C0 1.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" ,... considering as an alternative Specifically, if you need looser coupling between your entity object model and database, entity objects comprised of data coming from multiple tables, or more flexibility in modeling your entity objects, LINQ to Entities may be your answer How to Obtain LINQ Technically, there is no LINQ product to obtain LINQ is just the project code name for the query feature being added... 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 pay particular attention to how I 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(... queries against arrays and in- memory data collections Standard Query Operators are the static methods of the static System .Linq. Enumerable class that you use to create LINQ to Objects queries LINQ to XML LINQ to XML is the name given to the LINQ API dedicated to working with XML This interface was previously known as XLinq in older prereleases of LINQ Not only has Microsoft added the necessary XML... s in greetings where s.EndsWith( "LINQ" ) select s; foreach (var item in items) Console.WriteLine(item); ■Note The code in Listing 1-1 was added to a project created with the console application template in Visual Studio 2008 If one is not already present, you should add a using directive for the System .Linq namespace Running the previous code by pressing Ctrl+F5 outputs the following data to the console... select book.Element("title"); foreach(var title in titles) Console.WriteLine(title.Value); ■Note The code in Listing 1-2 requires adding the System.Xml .Linq. dll assembly to the project references if it is not already added Also notice that I 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: . 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. 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

Ngày đăng: 05/03/2014, 21:20

TỪ KHÓA LIÊN QUAN