Tải bản đầy đủ (.pdf) (133 trang)

Professional Visual Basic 2010 and .neT 4 phần 1 potx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (5.48 MB, 133 trang )

Simpo PDF Merge and Split Unregistered Version -
Simpo PDF Merge and Split Unregistered Version -
PROFESSIONAL
VISUAL BASIC® 2010 AND .NET 4
INTRODUCTION xxxv
PART I LANGUAGE CONSTRUCTS AND ENVIRONMENT 
CHAPTER 1 Visual Studio 2010 3
CHAPTER 2 Objects and Visual Basic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
CHAPTER 3 Custom Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .137
CHAPTER 4 The Common Language Runtime 211
CHAPTER 5 Declarative Programming with Visual Basic . . . . . . . . . . . . . . . . . . . . . . 253
CHAPTER 6 Exception Handling and Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
CHAPTER 7 Test-Driven Development 287
PART II BUSINESS OBJECTS AND DATA ACCESS 
CHAPTER 8 Arrays, Collections, and Generics 311
CHAPTER 9 Using XML with Visual Basic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
CHAPTER 10 ADO.NET and LINQ 389
CHAPTER 11 Data Access with the Entity Framework . . . . . . . . . . . . . . . . . . . . . . . . . 437
CHAPTER 12 Working with SQL Server 457
CHAPTER 13 Services (XML/WCF) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
PART III SMART CLIENT APPLICATIONS 
CHAPTER 14 Windows Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
CHAPTER 15 Advanced Windows Forms 575
CHAPTER 16 User Controls Combining WPF and Windows Forms . . . . . . . . . . . . . . 599
CHAPTER 17 WPF Desktop Applications 617
CHAPTER 18 Expression Blend 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 667
CHAPTER 19 Silverlight 679
Simpo PDF Merge and Split Unregistered Version -
PART IV INTERNET APPLICATIONS 
CHAPTER 20 Silverlight and Services 699
CHAPTER 21 Working with ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719


CHAPTER 22 ASP.NET Advanced Features 751
CHAPTER 23 ASP.NET MVC 787
CHAPTER 24 SharePoint 2010 Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 807
PART V LIBRARIES AND SPECIALIZED TOPICS 
CHAPTER 25 Visual Studio Tools for Oce 843
CHAPTER 26 Windows Workflow Foundation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 881
CHAPTER 27 Localization 905
CHAPTER 28 COM-Interop 929
CHAPTER 29 Network Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 949
CHAPTER 30 Application Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 981
CHAPTER 31 Assemblies and Reflection 1001
CHAPTER 32 Security in the .NET Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1021
CHAPTER 33 Parallel Programming Using Tasks and Threads . . . . . . . . . . . . . . . . . .1051
CHAPTER 34 Deployment 1101
APPENDIX A The Visual Basic Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1137
APPENDIX B Visual Basic Power Packs Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1151
APPENDIX C Workflow 2008 Specifics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1165
APPENDIX D Enterprise Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1185
APPENDIX E Programming for the Cloud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1205
INDEX 1233
Simpo PDF Merge and Split Unregistered Version -
PROFESSIONAL
Visual Basic® 2010 and .NET 4
Simpo PDF Merge and Split Unregistered Version -
Simpo PDF Merge and Split Unregistered Version -
PROFESSIONAL
Visual Basic® 2010 and .NET 4
Bill Sheldon
Billy Hollis
Kent Sharkey

Jonathan Marbutt
Rob Windsor
Gastón C. Hillar
Simpo PDF Merge and Split Unregistered Version -
Professional Visual Basic® 2010 and .NET 4
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2010 by Wiley Publishing, Inc., Indianapolis, Indiana
Published by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-0-470-50224-2
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means,
electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of
the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through
payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923,
(978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions
Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or
online at />Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect
to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without
limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional
materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the
understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional
assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author
shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation
and/or a potential source of further information does not mean that the author or the publisher endorses the information the

organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web
sites listed in this work may have changed or disappeared between when this work was written and when it is read.
For general information on our other products and services please contact our Customer Care Department within the United
States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in
electronic books.
Library of Congress Control Number: 2010921246
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are
trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries,
and may not be used without written permission. Visual Basic is a registered trademark of Microsoft Corporation in the United
States and/or other countries. All other trademarks are the property of their respective owners. Wiley Publishing, Inc. is not
associated with any product or vendor mentioned in this book.
Simpo PDF Merge and Split Unregistered Version -
To my wonderful wife, Tracie, who is forced to carry on while
I isolate myself to concentrate on writing. And to the next
generation of children who have joined our extended Sheldon
family (my own and my brothers’) in the past five years — Nick,
Elena, Ben, Billy V, Abigail, and Johnny — each and every
one of you is a valuable part of our lives.
—Bill Sheldon
I owe tremendous thanks to my family, who have somehow
learned to put up with marathon writing sessions, and
to my business partner, Gary Bailey, for keeping
our clients happy while I’m writing.
—Billy Hollis
To Babi, for keeping me alive and putting up with
me — hopefully, for a long time to come.
—Kent Sharkey
To my beautiful wife, Jennifer, who was my greatest
encouragement despite the long days of writing and working.

And to my loving daughter, Kathryn, who always managed to
put a smile on my face after a long day.
—Jonathan Marbutt
To my Dad, who did not complain too much about the
weekends I spent writing instead of playing golf with him.
—Rob Windsor
To my son, Kevin
—Gastón Hillar
Simpo PDF Merge and Split Unregistered Version -
Simpo PDF Merge and Split Unregistered Version -
ABOUT THE AUTHORS
BILL SHELDON is a software architect and engineer, originally from Baltimore, Maryland.
Holding a degree in computer science from the Illinois Institute of Technology (IIT), Bill has
been actively employed as a software engineer since resigning his commission with the United
States Navy. He is a Microsoft MVP for Visual Basic employed in Carlsbad, California. Bill also
works as an instructor for .NET courses at the University of California San Diego Extension. In
addition to writing books, Bill has published dozens of articles, including the Developer Update
Newsletter, SQL Server Magazine feature articles, and other Penton publications. He is an established online
presenter for MSDN and speaks at live events such as VSLive, DevConnections, Office Developers Conference,
and community events such as user groups and code camp. Bill is an avid cyclist and is active in the fight against
diabetes. Bill can be tracked down through his blog:
www.nerdnotes.net/blog or via Twitter: NerdNotes.
BILLY HOLLIS is an author and software consultant based in Nashville, Tennessee. Billy was
co-author of the first book ever published on Visual Basic .NET, as well as many other
books on software development. He is a member of the Microsoft Regional Director program
and a Microsoft MVP. In 2002, Billy was selected as one of the original .NET “Software
Legends.” He is heavily involved with consulting, training, and development on the .NET
platform, focusing on architecture, smart-client development, commercial packages, and
user-interface technologies. He regularly speaks on software development at major conferences all over the
world, including Microsoft’s PDC and TechEd events, DevConnections, VSLive, and architecture events such

as the Patterns and Practices Architect Summit.
KENT SHARKEY is an independent consultant who lives and codes in Comox, British
Columbia. Before going solo, Kent worked at Microsoft as a technical evangelist and content
strategist, promoting the use of .NET technologies. He lives with his wife, Margaret, and three
“children” — Squirrel, Cica, and Toffee.
JONATHAN MARBUTT is Vice President of Development for WayCool Software, Inc., based
in Birmingham, AL. He has been working professionally in software development since
1996, where he has covered various Microsoft technologies from VB6 to .NET. Over the
recent years, Jonathan has been developing with Silverlight to build Rich Internet Line of
Business applications for the non-profit sector. Through this development, he is beginning
to focus on User Experience (UX) by utilizing Microsoft products like Expression Blend
and technologies like Silverlight. For more information,contact Jonathan at
www.jmtechware.com.
ROB WINDSOR is a developer, trainer, writer and Senior Consultant with ObjectSharp
Consulting — a Microsoft Gold Partner based in Toronto, Canada. He has over fifteen years
experience developing rich-client and web applications with Delphi, VB, C# and VB.NET and
is currently spending a majority of his time working with SharePoint. Rob is a member of both
the INETA Speakers Bureau and the MSDN Canada Speakers Bureau and is a regular speaker
at conferences, code camps, and user groups across North America and Europe. He is President
of the Toronto Visual Basic User Group and has been recognized as a Microsoft Most Valuable
Professional for his involvement in the developer community.
Simpo PDF Merge and Split Unregistered Version -
GASTÓN C. HILLAR has been working with computers since he was eight. He began
programming with the legendary Texas TI-99/4A and Commodore 64 home computers
in the early 80s. He has worked as developer, architect, and project manager for many
companies in Buenos Aires, Argentina. Now, he is an independent IT consultant working
for several Spanish, German, and Latin American companies, and a freelance author. He is
always looking for new adventures around the world.
Gastón is the author of more than forty books in Spanish and has written two books in English. He
contributes to Dr. Dobb’s Go Parallel programming portal at

www.ddj.com/go-parallel/, Dr. Dobb’s at
, and is a guest blogger at Intel Software Network at .
He lives with his wife, Vanesa, and his son, Kevin. When not tinkering with computers, he enjoys
developing and playing with wireless virtual reality devices and electronics toys with his father, his son, and
his nephew Nico.
You can reach him at:

You can follow him on Twitter at: />Gastón’s blog is at:
ABOUT THE TECHNICAL EDITORS
DIANNE SIEBOLD is a software developer and writer specializing in VB, C#, .NET Framework, WCF, ADO,
and SQL Server. She has worked for a number of Microsoft partners writing enterprise applications with an
emphasis on services and data access. Currently, she works for Microsoft writing developer documentation in
the Dynamics product group. Reach her by e-mail at

DOUG PARSONS is a .NET Software Architect and professional Technical Editor who specializes in C#,
SQL Server, and numerous architectural paradigms. Over the course of his career, he has worked on a
myriad of projects; most notably, however, was the United States 2008 Presidential Campaign website of
John McCain. He is currently employed by NJI New Media, writing software for clients of a predominantly
political nature. He can be reached by email at

DOUG WATERFIELD is a software architect and engineer who lives with his family in Avon, Indiana.
Since earning a degree in computer science from Rose-Hulman Institute of Technology, Doug has been
designing and developing commercial and enterprise applications in a wide variety of technologies. Doug
led development teams and departments for several firms before becoming an independent consultant with a
focus on .NET technologies. He is a retired officer in the US Army Reserve and serves as a volunteer leader
in Cub Scouts and Boy Scouts.
Simpo PDF Merge and Split Unregistered Version -
CREDITS
ACQUISITIONS EDITOR
Paul Reese

SENIOR PROJECT EDITOR
Adaobi Obi Tulton
TECHNICAL EDITORS
Dianne Siebold
Doug Parsons
Doug Waterfield
SENIOR PRODUCTION EDITOR
Debra Banninger
COPY EDITOR
Luann Rou
EDITORIAL DIRECTOR
Robyn B. Siesky
EDITORIAL MANAGER
Mary Beth Wakefield
ASSOCIATE DIRECTOR OF MARKETING
David Mayhew
PRODUCTION MANAGER
Tim Tate
VICE PRESIDENT AND EXECUTIVE GROUP
PUBLISHER
Richard Swadley
VICE PRESIDENT AND EXECUTIVE PUBLISHER
Barry Pruett
ASSOCIATE PUBLISHER
Jim Minatel
PROJECT COORDINATOR, COVER
Lynsey Stanford
PROOFREADERS
Nancy Carrasco
Beth Prouty, Word One

INDEXER
Robert Swanson
COVER DESIGNER
Michael E. Trent
COVER IMAGE
© Dan Barnes/istockphoto
Simpo PDF Merge and Split Unregistered Version -
Simpo PDF Merge and Split Unregistered Version -
ACKNOWLEDGMENTS
AS WITH ANY MAJOR PROJECT PUTTING A BOOK OF this size and scope together is a team effort and
we as authors were really lucky to have such a great support team helping to keep us on track and focused.
I’d like to publicly call out and thank our editor, Adaobi, who managed to turn around several of the late
chapters (those would be mine) in an incredibly short time, and our technical editors, in particular Dianne,
who did an outstanding job. They found hundreds of issues so that our readers wouldn’t need to, and
helped ensure that everything worked and flowed in a logical fashion.
—Bill Sheldon
WHILE WRITING can be a solitary activity, writing for a book definitely is not, and I have many people to
thank for getting me here.
Thank you to all my coworkers who picked up the slack while I worked on this (Oh, wait — I work alone —
never mind). Thank you to my co-authors, and my fine editors: Adaobi Obi Tulton, Paul Reese, and Dianne
Siebold. If there is any quality here, it is likely due to their hard work.
I am definitely grateful to all the people who regularly put up with my negativity, and help me to become
better: Eileen, Chris, Tharun, Kraig and Duncan. Thank you, thank you, thank you.
And finally, thanks to all of you that have selected this book. I hope it helps.
—Kent Sharkey
THANKS TO BETH MASSI for being too busy to work on this project and thanks to the people at Wrox for
accepting Beth’s suggestion that I would be a suitable replacement.
As a first time author, I have to give special thanks to Adaobi Obi Tulton, Dianne Siebold, Doug Parsons,
Doug Waterfield, and Luann Rouff for helping me make my work appear as if it was written by a
professional author. I’m sure it wasn’t easy.

Finally, I’d like to thank those who helped me advance professionally to the point that this opportunity was
even possible: Craig Flanagan, Sasha Krsmanovic, Jean-Rene Roy, Mark Dunn, Carl Franklin, Richard
Campbell, all the Canadian RDs, and everyone at ObjectSharp.
—Rob Windsor
I WISH TO ACKNOWLEDGE Paul Reese and Adaobi Obi Tulton; they had a lot of patience and they allowed
me to make the necessary changes to my chapter in order to include the most appropriate information about
the new parallel programming features introduced in .NET Framework 4 and Visual Basic 2010.
Special thanks go to my wife, Vanesa S. Olsen, because she understood that I needed to work with many
computers at the same time to test each code snippet.
—Gastón C. Hillar
Simpo PDF Merge and Split Unregistered Version -
Simpo PDF Merge and Split Unregistered Version -
CONTENTS
INTRODUCTION xxxv
PART I: LANGUAGE CONSTRUCTS AND ENVIRONMENT
CHAPTER 1: VISUAL STUDIO 2010 3
Visual Studio 2010: Express through Ultimate 4
Visual Basic Keywords and Syntax 7
Console Applications 10
Creating a Project from a Project Template 11
The Solution Explorer 14
Project Properties 15
Assembly Information Screen 16
Compiler Settings 17
Debug Properties 21
References 22
Resources 24
Settings 25
Other Project Property Tabs 28
Project ProVB_VS2010 28

Form Properties Set in Code 31
Additional Components for Visual Studio 39
Enhancing a Sample Application 40
Customizing the Code 41
Building Applications 45
Reusing Your First Windows Form 52
Useful Features of Visual Studio 2010 54
Build Configurations 54
The Task List 56
The Command Window 57
Server Explorer 57
Recording and Using Macros in Visual Studio 2010 58
Class Diagrams 60
Application Lifecycle Management 61
Performance Tools 64
Summary 66
Simpo PDF Merge and Split Unregistered Version -
CONTENTS
xvi
CHAPTER 2: OBJECTS AND VISUAL BASIC 67
Object-Oriented Terminology 68
Objects, Classes, and Instances 68
Composition of an Object 69
System.Object 72
Working With Visual Basic Types 72
Value and Reference Types 73
Primitive Types 75
Commands: Conditional 76
If Then 77
Comparison Operators 77

Select Case 79
Value Types (Structures) 79
Boolean 80
Integer Types 81
Unsigned Types 82
Decimal Types 82
Char and Byte 85
DateTime 85
Reference Types (Classes) 86
The Object Class 86
The String Class 87
XML Literals 91
The DBNull Class and IsDBNull Function 92
Parameter Passing 93
ParamArray 94
Variable Scope 94
Working with Objects 95
Objects Declaration and Instantiation 95
Object References 96
Dereferencing Objects 97
Early Binding versus Late Binding 97
Data Type Conversions 98
Performing Explicit Conversions 99
Creating Classes 103
Basic Classes 103
Handling Events 113
Handling Multiple Events 113
Simpo PDF Merge and Split Unregistered Version -
CONTENTS
xvii

The WithEvents Keyword 114
Raising Events 114
Declaring and Raising Custom Events 115
Receiving Events with WithEvents 116
Receiving Events with AddHandler 117
Constructor Methods 119
Termination and Cleanup 119
Advanced Concepts 120
Overloading Methods 121
Overloading Constructor Methods 123
Shared Methods, Variables, and Events 124
Operator Overloading 128
Delegates 130
Classes versus Components 134
Lambdas 135
Summary 136
CHAPTER 3: CUSTOM OBJECTS 137
Inheritance 138
Implementing Inheritance 139
Interacting with the Base Class, Your Class, and Your Object 159
Simple Constructors 164
Creating an Abstract Base Class 175
Multiple Interfaces 177
Object Interfaces 177
Secondary Interfaces 178
Abstraction 184
Encapsulation 187
Polymorphism 189
Method Signatures 189
Inheritance 198

When to Use Inheritance 198
How Deep to Go? 205
Summary 208
CHAPTER 4: THE COMMON LANGUAGE RUNTIME 211
Elements of a .NET Application 212
Modules 212
Assemblies 213
Types 214
Simpo PDF Merge and Split Unregistered Version -
CONTENTS
xviii
Versioning and Deployment 214
Better Support for Versioning 214
Major.Minor.Build.Revision 215
Better Deployment 215
Cross-Language Integration 216
The Common Type System 216
Metadata 217
Better Support for Metadata 218
Attributes 218
The Reflection API 220
IL Disassembler 221
Memory Management 221
Traditional Garbage Collection 222
Faster Memory Allocation for Objects 228
Garbage Collector Optimizations 229
Namespaces 231
What Is a Namespace? 231
Namespaces and References 234
Common Namespaces 236

Importing and Aliasing Namespaces 238
Aliasing Namespaces 239
Referencing Namespaces in ASP.NET 240
Creating Your Own Namespaces 240
The My Keyword 242
My.Application 243
My.Computer 246
My.Forms Namespace 249
My.Resources 249
My.User 250
Extending the My Namespace 250
Summary 252
CHAPTER 5: DECLARATIVE PROGRAMMING
WITH VISUAL BASIC 253
Declarative Programming and Visual Basic 254
Using XAML to Create a Window 255
XAML Syntax 258
XAML Language Basics 259
XAML Directives 261
Using XAML to Declare a Workflow 262
Summary 264
Simpo PDF Merge and Split Unregistered Version -
CONTENTS
xix
CHAPTER 6: EXCEPTION HANDLING AND DEBUGGING 267
New in Visual Studio 2010 Team System: Historical Debugging 267
Notes on Compatibility with VB6 268
Exceptions in .NET 268
Important Properties and Methods of an Exception 268
Structured Exception-Handling Keywords 269

The Try, Catch, and Finally Keywords 270
The Throw Keyword 271
Throwing a New Exception 272
The Exit Try Statement 273
Nested Try Structures 274
Using Exception Properties 275
The Message Property 276
The InnerException and TargetSite Properties 276
Interoperability with VB6-Style Error Handling 279
Error Logging 280
The Event Log 280
Events, Methods, and Properties 281
Writing to Trace Files 283
Summary 284
CHAPTER 7: TESTDRIVEN DEVELOPMENT 287
When and How to Test 288
Using Assertions 288
TDD Tools in Visual Studio 290
UnitTesting Walk-Through 291
Creating a Test 291
Running a Test 293
Testing Data Access Code 295
Using the Generate from Usage Feature 302
Other Visual Studio Editions 305
Third Party Testing Frameworks 306
Summary 307
PART II: BUSINESS OBJECTS AND DATA ACCESS
CHAPTER 8: ARRAYS, COLLECTIONS, AND GENERICS 311
Arrays 312
Multidimensional Arrays 313

The UBound Function 314
Simpo PDF Merge and Split Unregistered Version -
CONTENTS
xx
The ReDim Statement 314
The Preserve Keyword 315
Collections 315
Generics 320
Using Generics 321
Nullable Types 322
Generic Types 322
Generic Methods 326
Creating Generics 327
Generic Types 327
Generic Methods 333
Constraints 334
Generics and Late Binding 337
Covariance and Contravariance 337
Summary 339
CHAPTER 9: USING XML WITH VISUAL BASIC 341
An Introduction to XML 342
XML Serialization 343
Source Code Style Attributes 347
System.Xml Document Support 348
XML Stream-Style Parsers 348
Writing an XML Stream 349
Reading an XML Stream 351
Document Object Model (DOM) 359
XSL Transformations 363
XSLT Transforming between XML Standards 366

Other Classes and Interfaces in System.Xml.Xsl 368
XML in ASP.NET 369
The XmlDataSource Server Control 369
The XmlDataSource Control’s Namespace Problem 373
The Xml Server Control 373
LINQ to XML 375
LINQ Helper XML Objects 375
XDocument 375
XElement 375
XNamespace 376
XAttribute 378
Visual Basic and XML Literals 379
Using LINQ to Query XML Documents 380
Simpo PDF Merge and Split Unregistered Version -
CONTENTS
xxi
Querying Static XML Documents 380
Querying Dynamic XML Documents 381
Working with the XML Document 382
Reading from an XML Document 382
Writing to an XML Document 384
Lambda Expressions in Visual Basic 385
Summary 387
CHAPTER 10: ADO.NET AND LINQ 389
ADO.NET Architecture 390
Basic ADO.NET Features 391
Common ADO.NET Tasks 391
Basic ADO.NET Namespaces and Classes 395
ADO.NET Components 396
.NET Data Providers 398

Connection Object 398
Command Object 399
Using Stored Procedures with Command Objects 399
DataReader Object 402
Executing Commands Asynchronously 404
DataAdapter Objects 406
SQL Server .NET Data Provider 409
OLE DB .NET Data Provider 409
The DataSet Component 410
DataTableCollection 410
DataRelationCollection 410
ExtendedProperties 411
Creating and Using DataSet Objects 411
ADO.NET DataTable Objects 413
Advanced ADO.NET Features of the DataSet and DataTable Objects 414
Working with the Common Provider Model 416
Connection Pooling in ADO.NET 418
Transactions and System.Transactions 418
Creating Transactions 419
Creating Resource Managers 421
LINQ to SQL 421
LINQ to SQL and Visual Basic 422
Retrieving Data Using LINQ to SQL: Creating the Console Application 422
Introducing the O/R Designer 423
Creating the Product Object 424
Simpo PDF Merge and Split Unregistered Version -
CONTENTS
xxii
How Objects Map to LINQ Objects 425
The DataContext Object 426

The Table(TEntity) Object 428
Querying the Database 428
Using Query Expressions 429
Query Expressions in Detail 429
Filtering Using Expressions 429
Performing Joins 430
Grouping Items 431
Stored Procedures 432
Updating the Database 433
Summary 435
CHAPTER 11: DATA ACCESS WITH THE ENTITY FRAMEWORK 437
Object-Relational Mapping 438
Entity Framework Architecture 438
Conceptual Model 439
Storage Model 442
Mapping Model 443
LINQ to Entities 443
The ObjectContext 445
Mapping Objects to Entities 446
Simple Mapping 446
Using a Single Table for Multiple Objects 448
Using Multiple Tables for an Object 450
Generating the Database from a Model 452
Updating the Model 454
Summary 456
CHAPTER 12: WORKING WITH SQL SERVER 457
SQL Server Compact 458
Connecting to a SQL Server Compact Database 459
Synchronizing Data 462
SQL Server’s Built-in XML Features 468

CLR Integration In SQL Server 470
Deciding between T-SQL and Visual Basic 470
Creating User-Defined Types 471
Creating Stored Procedures 483
Exposing Web Services from SQL Server 489
SQL Server 2008 Features 494
Simpo PDF Merge and Split Unregistered Version -
CONTENTS
xxiii
WCF Data Services 495
REST 495
Atom and JSON 495
Exposing Data Using WCF Data Services 497
WCF Data Services Client Library 501
Summary 505
CHAPTER 13: SERVICES XML/WCF 507
Introduction to Services 508
The Network Angle 508
Application Development 508
Merging the Network and Application Development 508
The Foundations of Web Services 509
The Problems 510
Some Other Players 511
Web Services 511
What Makes a WCF Service 512
The Larger Move to SOA 513
Capabilities of WCF 514
Contracts and Metadata 514
Working with the WS-* Protocols 515
Building a WCF Service 516

Building a WCF Consumer 523
Adding a Service Reference 523
Reviewing the Reference 525
Configuration File Changes 528
Writing the Consumption Code 529
Working with Data Contracts 531
Building a Service with a Data Contract 532
Namespaces 533
Building the Host 533
Building the Consumer 534
Looking at WSDL and the Schema for HelloCustomerService 536
Summary 538
PART III: SMART CLIENT APPLICATIONS
CHAPTER 14: WINDOWS FORMS 541
The System.Windows.Forms Namespace 541
Using Forms 542
Setting a Startup Form 542
Simpo PDF Merge and Split Unregistered Version -

×