this print for content only—size & color not accurate spine = 1.176" 624 page countPro LINQ: Language Integrated Query in C# 2008 Dear Reader, Pro LINQ: Language Integrated Query in C# 2
Trang 1this print for content only—size & color not accurate spine = 1.176" 624 page count
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
Pro
LINQ
Language Integrated Query
in C# 2008
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.
Pro
Trang 3Pro LINQ
Language Integrated Query
in C# 2008
■ ■ ■
Joseph C Rattz, Jr.
Trang 4ISBN-13 (pbk): 978-1-59059-789-7
ISBN-10 (pbk): 1-59059-789-3
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark
Lead Editor: Ewan Buckingham
Technical Reviewer: Fabio Ferracchiati
Editorial Board: Steve Anglin, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Jason Gilmore, Kevin Goff, Jonathan Hassell, Matthew Moodie, Joseph Ottinger, Jeffrey Pepper, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh
Senior Project Manager: Tracy Brown Collins
Copy Editors: Heather Lang and Jennifer Whipple
Associate Production Director: Kari Brooks-Copony
Production Editor: Katie Stence
Compositor: Pat Christenson
Proofreader: Dan Shaw
Indexer: Carol Burbo
Artist: Kinetic Publishing Services, LLC
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013 Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com, or visit http://www.springeronline.com
For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600,
www.apress.com
The information in this book is distributed on an “as is” basis, without warranty Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly
by the information contained in this work
The source code for this book is available to readers at http://www.apress.com You will need to answer questions pertaining to this book in order to successfully download the code
Trang 5For my amazing wife Vickey, who managed to keep our house
a home all by herself for these past, long 17 months
Thank you for doing the things that gave me time to work on this book.
Trang 6XContainer.Descendants() method, traversing
236–237 XContainer.Elements() method, 232–234
vs Extensions.Elements operator, 273–274
XContainer.Nodes() method, 228–229
XDeclaration class, 210–211
XDocument class, 212–213
XDocument.Load() method, 220–222
XDocument.Save() methods, 218–219
XDocumentType class, 211–212
XDocumentType.InteralSubset, 251
XDocumentType.Name, 251
XDocumentType.PublicId, 251
XDocumentType.SystemId, 251
XElement class, 4
XElement object
accessing XML document from, 226–227
instantiating, 206
traversing down recursively from, 236–237
traversing up from, 227–228, 235–236
XElement.AddFirst method, 215
XElement.AncestorsAndSelf() method, 235–236
XElement.Attribute() method, 257–258
XElement.Attributes() method, 258
XElement.DescendantsAndSelf() method,
237–238 XElement.FirstAttribute property, 255
XElement.LastAttribute property, 257
XElement.Load() method, 222–223
XElement.RemoveAll() method, 249
XElement.ReplaceAll() method, 252–253
XElement.Save() methods, 219–220
XLinq See LINQ to XML
XML additional capabilities, 301–336 desired structure, 188
LINQ to, 187–192 querying with XPath syntax, 335 simple example, 187–188 XML annotations, 263–267 XML attributes, 255–263 XML data
modifying, 242–253 query joining database data with, 583
XML documents See also documents
allowing user edit of book participant, 331–332
creating for validating, 330–331 creating new for transformed version, 311 creating with book participants, 311 transforming using function construction, 312–314
transforming with XSLT, 310–311 unsuccessfully validating against XSD schema, 325–329
unsuccessfully validating XML element, 332–334
validating, 322–325, 331 XML element, successfully validating, 330 XML events
examples, 268–272 registering for, 267 XML external mapping, file schema, 484–485 XML input, 220–222
Trang 7600 ■I N D E X
XML mapping files
abbreviated external, 517–518
considerations for using, 393
vs DBML intermediate file, 398
XML namespaces See namespaces
XML output, 218–220
XML schema
creating, 321–322
creating using functional construction,
194–195 obtaining, 321–334
XML strings, parsing, 223
XML transformations See also transformations
simplifying with helper methods, 314
tips for performing, 314–319
XML traversal, 224–242
properties, 225–228
XML tree
adding nodes to, 242–243
for examples in LINQ to XML, 312
generating with a LINQ query, 207–208
problems removing nodes from, 203–205
producing, 200
recursively traversing up, 234–235
traversing backward, 225–226
traversing down, 228–229
traversing forward through, 225
XML tree construction
deferred execution of, 217
immediate execution of, 216
XMLHelper method, 191
XmlMappingSource object, 518
XName object
creating, 213
for XML elements, 198–199
XNamespace class, 214 XNode.AddAfterSelf() method, 246 XNode.AddBeforeSelf() method, 244–245 XNode.Ancestors() method, 234–235 XNode.ElementsAfterSelf() method, 239–240 XNode.ElementsBeforeSelf() method, 241–242 XNode.NextNode property, 225
XNode.NodesAfterSelf() method, 238–239 XNode.NodesBeforeSelf() method, 240–241 XNode.PreviousNode property, 225–226 XNode.Remove() method247–248 XNodeDocumentOrderComparer class, 202 XNodeEqualityComparer class, 202 XObject event handling, 269–272 XObject.AddAnnotation() method, 263 XObject.Annotation()/XObject.Annotations() method, 263
XObject.Changed event, 268 XObject.Changing event, 268 XObject.Document property, accessing XML document via, 226–227
XObject.Parent property, 227–228 XObject.RemoveAnnotations() method, 264 XProcessingInstruction class, 214–215 XProcessingInstruction.Data, 252 XProcessingInstruction.Target, 252 XSLT trasformations, advantages of, 309–310 XStreamingElement class, 216–217
XText object, creating text node with, 217–218 XText.Value, on XText objects, 250
■ Y
yield keyword, for writing enumerators, 55 [Your]DataContext class, 499–500
constructor prototype connecting to database, 511–512