Book description
Language Integrated Query (LINQ), as well as the C# 3.0 and VB 9.0 language extensions to support it, is the most import single new feature of Visual Studio 2008 and the .NET Framework 3.x. LINQ is Microsoft's first attempt to define a universal query language for a diverse set of in-memory collections of generic objects, entities persisted in relational database tables, and element and attributes of XML documents or fragments, as well as a wide variety of other data types, such as RSS and Atom syndication feeds. Microsoft invested millions of dollars in Anders Hejlsberg and his C# design and development groups to add new features to C# 3.0—such as lambda expressions, anonymous types, and extension methods—specifically to support LINQ Standard Query Operators (SQOs) and query expressions as a part of the language itself.
Corresponding additions to VB 9.0 followed the C# team's lead, but VB's implementation of LINQ to XML offers a remarkable new addition to the language: XML literals. VB's LINQ to XML implementation includes XML literals, which treat well-formed XML documents or fragments as part of the VB language, rather than requiring translation of element and attribute names and values from strings to XML DOM nodes and values.
This book concentrates on hands-on development of practical Windows and Web applications that demonstrate C# and VB programming techniques to bring you up to speed on LINQ technologies. The first half of the book covers LINQ Standard Query Operators (SQOs) and the concrete implementations of LINQ for querying collections that implement generic IEnumerable, IQueryable, or both interfaces. The second half is devoted to the ADO.NET Entity Framework, Entity Data Model, Entity SQL (eSQL) and LINQ to Entities. Most code examples emulate real-world data sources, such as the Northwind sample database running on SQL Server 2005 or 2008 Express Edition, and collections derived from its tables. Code examples are C# and VB Windows form or Web site/application projects not, except in the first chapter, simple command-line projects. You can't gain a feel for the behavior or performance of LINQ queries with "Hello World" projects that process arrays of a few integers or a few first and last names.
This book is intended for experienced .NET developers using C# or VB who want to gain the maximum advantage from the query-processing capabilities of LINQ implementations in Visual Studio 2008—LINQ to Objects, LINQ to SQL, LINQ to DataSets, and LINQ to XML—as well as the object/relational mapping (O/RM) features of VS 2008 SP1's Entity Framework/Entity Data Model and LINQ to Entities and the increasing number of open-source LINQ implementations by third-party developers.
Basic familiarity with generics and other language features introduced by .NET 2.0, the Visual Studio integrated development environment (IDE), and relational database management systems (RDBMSs), especially Microsoft SQL Server 200x, is assumed. Experience with SQL Server's Transact-SQL (T-SQL) query language and stored procedures will be helpful but is not required. Proficiency with VS 2005, .NET 2.0, C# 2.0, or VB 8.0 will aid your initial understanding of the book's C# 3.0 or VB 9.0 code samples but isn't a prerequisite.
Microsoft's .NET code samples are primarily written in C#. All code samples in this book's chapters and sample projects have C# and VB versions unless they're written in T-SQL or JavaScript.
Professional ADO.NET 3.5: LINQ and the Entity Framework concentrates on programming the System.Linq
and System.Linq.Expressions
namespaces for LINQ to Objects, System.Data.Linq
for LINQ to SQL, System.Data.Linq
for LINQ to DataSet, System.Xml.Linq
for LINQ to XML, and System.Data.Entity
and System.Web.Entity
for EF's Entity SQL.
"Taking a New Approach to Data Access in ADO.NET 3.5," uses simple C# and VB code examples to demonstrate LINQ to Objects queries against in-memory objects and databinding with LINQ-populated generic List collections, object/relational mapping (O/RM) with LINQ to SQL, joining
DataTableS
with LINQ to DataSets, creatingEntitySetS
with LINQ to Entities, querying and manipulating XML InfoSets with LINQ to XML, and performing queries against strongly typed XML documents with LINQ to XSD."Understanding LINQ Architecture and Implementation," begins with the namespaces and C# and VB language extensions to support LINQ, LINQ Standard Query Operators (SQOs), expression trees and compiled queries, and a preview of domain-specific implementations. C# and VB sample projects demonstrate object, array, and collection initializers, extension methods, anonymous types, predicates, lambda expressions, and simple query expressions.
"Executing LINQ Query Expressions with LINQ to Objects," classifies the 50 SQOs into operator groups: Restriction, Projection, Partitioning, Join, Concatenation, Ordering, Grouping, Set, Conversion, and Equality, and then lists their keywords in C# and VB. VS 2008 SP1 includes C# and VB versions of the LINQ Project Sample Query Explorer, but the two Explorers don't use real-world collections as data sources. This describes a LINQ in-memory object generator (LIMOG) utility program that writes C# 3.0 or VB 9.0 class declarations for representative business objects that are more complex than those used by the LINQ Project Sample Query Explorers. Sample C# and VB queries with these business objects as data sources are more expressive than those using a arrays of a few integers or last names.
"Working with Advanced Query Operators and Expressions," introduces LINQ queries against object graphs with entities that have related (associated) entities. This begins with examples of aggregate operators, explains use of the
Let
temporary local variable operator, shows you how to useGroup By
with aggregate queries, conduct the equivalent of left outer joins, and take advantage of theContains()
SQO to emulate SQL'sIN()
function. You learn how to compile queries for improved performance, and create mock object classes for testing without the overhead of queries against relational persistence stores."Using LINQ to SQL and the LinqDataSource," introduces LINQ to SQL as Microsoft's first O/RM tool to reach released products status and shows you how to autogenerate class files for entity types with the graphical O/R Designer or command-line
SqlMetal.exe.
This also explains how to edit*.dbml
mapping files in the Designer or XML Editor, instantiateDataContext
objects, and use LINQ to SQL as a Data Access Layer (DAL) with T-SQL queries or stored procedures. Closes with a tutorial for using the ASP.NET LinqDataSource control with Web sites or applications."Querying DataTables with LINQ to DataSets," begins with a comparison of
DataSet
andDataContext
objects and features, followed by a description of theDataSetExtensions
. Next comes querying untyped and typed DataSets, creating lookup lists, and generatingLinqDataViewS
for databinding with theAsDataView()
method. This ends with a tutorial that shows you how to copy LINQ query results toDataTableS
."Manipulating Documents with LINQ to XML," describes one of LINQ most powerful capabilities: managing XML Infosets. This demonstrates that LINQ to XML has query and navigation capabilities that equal or surpasses XQuery 1.0 and XPath 2.0. It also shows LINQ to XML document transformation can replace XQuery and XSLT 1.0+ in the majority of common use cases. You learn how to use VB 9.0's XML literals to constructs XML documents, use
GroupJoin()
to produce hierarchical documents, and work with XML namespaces in C# and VB."Exploring Third-Party and Emerging LINQ Implementations," describes Microsoft's Parallel LINQ (also called PLINQ) for taking advantage of multiple CPU cores in LINQ to Objects queries, LINQ to REST for translating LINQ queries into Representational State Transfer URLs that define requests to a Web service with the HTML GET, POST, PUT, and DELETE methods, and Bart De Smet's LINQ to Active Directory and LINQ to SharePoint third-party implementations.
"Raising the Level of Data Abstraction with the Entity Data Model," starts with a guided tour of the development of EDM and EF as an O/RM tool and heir apparent to ADO.NET DataSets, provides a brief description of the entity-relationship (E-R) data model and diagrams, and then delivers a detailed analysis of EF architecture. Next comes an introduction to the Entity SQL (eSQL) language, eSQL queries, client views, and Object Services, including the
ObjectContext
,MetadataWorkspace
, andObjectStateManager
. Later chapters describe eSQL and these objects in greater detail. Two C# and VB sample projects expand on the eSQL query and Object Services sample code."Defining Conceptual, Mapping, and Storage Schema Layers," provides detailed insight into the structure of the
*.edmx
file that generates the*.ssdl
(storage schema data language),*.msl
(mapping schema language), and*.csdl
files at runtime. You learn how to edit the*
.edmx file manually to accommodate modifications that the graphic EDM Designer can't handle. You learn how to implement the Table-per-Hierarchy (TPH) inheritance model and traverse the MetadataWorkspace to obtain property values. Four C# and VB sample projects demonstrate mapping, substituting stored procedures for queries, and TPH inheritance."Introducing Entity SQL," examines EF's new eSQL dialect that adds keywords to address the differences between querying entities and relational tables. You learn to use Zlatko Michaelov's eBlast utility to write and analyze eSQL queries, then dig into differences between eSQL and T-SQL
SELECT
queries. (eSQL v1 doesn't supportINSERT, UPDATE, DELETE
and ...
Table of contents
- Copyright
- About the Author
- Credits
- Acknowledgments
- Introduction
-
I. Getting a Grip on ADO.NET 3.5
-
1. Taking a New Approach to Data Access in ADO.NET 3.5
-
1.1. Language Integrated Query (LINQ)
- 1.1.1. LINQ to Objects
- 1.1.2. LINQ to SQL
-
1.1.3. Programming the DataContext
- 1.1.3.1. Emulating Joins by Navigating Associations
- 1.1.3.2. Loading Child Objects Lazily or Eagerly
- 1.1.3.3. Creating Explicit Joins with LINQ Join ... On Expressions
- 1.1.3.4. Applying Operators to Emulate SQL Functions, Modifiers, and Operators
- 1.1.3.5. Updating Table Data
- 1.1.3.6. Generating a SQL Server Database with the OR Designer
- 1.1.3.7. LinqDataSource Control
- 1.1.4. LINQ to DataSets
- 1.1.5. LINQ to Entities
- 1.1.6. LINQ to XML
- 1.1.7. LINQ to XSD
- 1.2. The ADO.NET Entity Framework and Entity Data Model
- 1.3. Summary
-
1.1. Language Integrated Query (LINQ)
-
1. Taking a New Approach to Data Access in ADO.NET 3.5
-
II. Introducing Language Integrated Query
-
2. Understanding LINQ Architecture and Implementation
- 2.1. Namespaces That Support LINQ in .NET Fx 3.5
-
2.2. C# and VB Extensions to Support LINQ
- 2.2.1. Implicitly Typed Local Variables
- 2.2.2. Object Initializers
- 2.2.3. Array Initializers with Object Initializers
- 2.2.4. Collection Initializers
- 2.2.5. Anonymous Types
- 2.2.6. Extension Methods
- 2.2.7. Anonymous Methods and Generic Predicates
- 2.2.8. Lambda Expressions
- 2.2.9. Standard Query Operators
- 2.2.10. Expression Trees and Compiled Queries
- 2.2.11. The IQueryable<T> Interface and Domain-Specific LINQ Implementations
- 2.3. Summary
-
3. Executing LINQ Query Expressions with LINQ to Objects
- 3.1. Standard Query Operators by Group
- 3.2. SQOs as Keywords in C# 3.0 and VB 9.0
- 3.3. The LINQ Project Sample Query Explorers
- 3.4. Sample Classes for LINQ to Objects Code Examples
- 3.5. Restriction Operator: Where
- 3.6. Projection Operators
- 3.7. Partitioning Operators
- 3.8. Join Operators
- 3.9. Concatenation Operator: Concat
- 3.10. Ordering Operators
- 3.11. Grouping Operator: GroupBy
- 3.12. Set Operators
- 3.13. Conversion operators
- 3.14. Equality Operator: SequenceEqual
- 3.15. Element operators
- 3.16. Generation Operators
- 3.17. Quantifier Operators
- 3.18. Aggregate Operators
- 3.19. Summary
-
4. Working with Advanced Query Operators and Expressions
- 4.1. Exploring Basic Query Syntax for Aggregate Operators
- 4.2. Using Group By with Aggregate Queries
- 4.3. Taking Full Advantage of the Contains() SQO
- 4.4. Compiling Query Expression Trees to Improve Performance
- 4.5. Mocking Collections for Testing LINQ to SQL and LINQ to Entities Projects
- 4.6. Summary
-
2. Understanding LINQ Architecture and Implementation
-
III. Applying Domain-Specific LINQ Implementations
-
5. Using LINQ to SQL and the LinqDataSource
- 5.1. Object/Relational Mapping with LINQ to SQL
- 5.2. Using LINQ to SQL as a Data Access Layer
- 5.3. ASP.NET Databinding with the LinqDataSource Control
- 5.4. Databinding Windows Form Controls to Entities
- 5.5. Summary
- 6. Querying DataTables with LINQ to DataSet
-
7. Manipulating Documents with LINQ to XML
- 7.1. Integrating XML into the CLR
- 7.2. The System.Xml.Linq Namespace
- 7.3. Querying Basic XML Infosets
- 7.4. Composing XML Infosets
- 7.5. Grouping Elements and Aggregating Numeric Values of Business Documents
- 7.6. Working with XML Namespaces and Local Names
- 7.7. Performing Heterogeneous Joins and Lookup Operations
- 7.8. Summary
-
8. Exploring Third-Party and Emerging LINQ Implementations
- 8.1. Emerging Microsoft LINQ Implementations
- 8.2. Third-Party Domain-Specific LINQ Implementations
- 8.3. Summary
-
5. Using LINQ to SQL and the LinqDataSource
-
IV. Introducing the ADO.NET Entity Framework
-
9. Raising the Level of Data Abstraction with the Entity Data Model
- 9.1. Understanding the Entity-Relationship Model
- 9.2. Comprehending Entity Framework Architecture and Components
- 9.3. Working with the Entity Client, Entity SQL and Client Views
- 9.4. Taking Advantage of Object Services
- 9.5. Understanding the Persistence Ignorance Controversy
- 9.6. Summary
-
10. Defining Storage, Conceptual, and Mapping Layers
-
10.1. Exploring and Customizing the EDMX File
-
10.1.1. Storage Models (SSDL Content)
- 10.1.1.1. The EntityContainer Subgroup
- 10.1.1.2. EntityType Subgroups
- 10.1.1.3. The Product EntityType Subgroup
-
10.1.1.4. Function Subelements and Subgroups
- 10.1.1.4.1. Function Definitions for a DateTime Scalar Function and Product Stored Procedures
- 10.1.1.4.2. Function Imports to Assign Data Retrieval Stored Procedures to an EntitySet
- 10.1.1.4.3. Insert, Update, and Delete Function Mapping to EntityTypes
- 10.1.1.4.4. Update Stored Procedure Association Mapping in the Designer
- 10.1.1.5. Association Subgroups
- 10.1.2. Conceptual Models (CSDL Content)
- 10.1.3. Mapping (MSL Content)
-
10.1.1. Storage Models (SSDL Content)
- 10.2. Implementing Table-per-Hierarchy Inheritance
- 10.3. Traversing the MetadataWorkspace
- 10.4. Summary
-
10.1. Exploring and Customizing the EDMX File
-
11. Introducing Entity SQL
- 11.1. Using the eSqlBlast Entity SQL Query Utility
-
11.2. Understanding How Entity SQL Differs from Transact-SQL
- 11.2.1. Entity Alias Prefixes Are Mandatory
- 11.2.2. Explicit Projections Are Required
- 11.2.3. The VALUE Modifier Flattens Results
- 11.2.4. Dot-Notation Syntax Returns Many:One Navigation Properties
- 11.2.5. Nested Queries Are Required for One:Many Navigation Properties
- 11.2.6. JOINs Are the Last Resort
- 11.2.7. NAVIGATE is a Complex Substitute for Dot Notation or Nested Queries
- 11.2.8. REF, DEREF, CREATEREF, ROW, and KEY Manage Entity References
- 11.2.9. Type Constructors Create ROWs, Multisets, and Instances of EntityTypes
- 11.2.10. The UNION, INTERSECT, OVERLAPS, and EXCEPT Set Operators Require Sub-Queries
- 11.2.11. Sorting Collections Returned by Set Operators Requires a Nested Query
- 11.2.12. Set Operators ANYELEMENT and FLATTEN Work on Collections
- 11.2.13. SKIP and LIMIT Sub-Clauses of the ORDER BY Clause Handle Paging
- 11.2.14. IS OF, OFTYPE, and TREAT Are Type Operators for Polymorphic Queries
- 11.2.15. Subqueries That Return Aggregate Values for WHERE Clause Constraints Throw Exceptions
- 11.3. Executing eSQL Queries against the EntityClient
- 11.4. Using SQL Server Compact as an Entity Framework Data Store
- 11.5. Summary
-
9. Raising the Level of Data Abstraction with the Entity Data Model
-
V. Implementing the ADO.NET Entity Framework
-
12. Taking Advantage of Object Services and LINQ to Entities
- 12.1. Exploring the Generated Entity Classes
- 12.2. Executing eSQL ObjectQueries
- 12.3. Enabling Deferred or Eager Loading of Associated Entities
- 12.4. Ordering and Filtering Associated EntityCollections during Loading
- 12.5. Composing Query Builder Methods to Write ObjectQueries
- 12.6. Writing LINQ to Entities Queries
- 12.7. Parameterizing Object Queries
- 12.8. Summary
-
13. Updating Entities and Complex Types
- 13.1. Understanding the ObjectContext's ObjectStateManager and Its Children
- 13.2. Updating or Deleting Entities
- 13.3. Adding Entities
- 13.4. Refreshing Stale Entities
- 13.5. Validating Data Additions and Updates
- 13.6. Optimizing the ObjectContext Lifetime
- 13.7. Comparing the Performance of LINQ to Entities and Out-of-Band SQL Updates
- 13.8. Managing Optimistic Concurrency Conflicts
- 13.9. Performing CRUD Operations with Stored Procedures
- 13.10. Working with Complex Types
- 13.11. Summary
-
14. Binding Entities to Data-Aware Controls
-
14.1. Binding Windows Form Controls to Entities with Object Data Sources
- 14.1.1. Using the Load(), Include(), and Attach() Methods for Shaping Object Graphs
- 14.1.2. Selecting the Active Top-Level and Associated Entity Instances
- 14.1.3. Using Unbound ComboBoxes to Specify Associations
- 14.1.4. Setting Composite Primary-Key Members with Combo Boxes
- 14.1.5. Persisting Changes to the Data Store
- 14.2. Using the EntityDataSource with ASP.NET Server Controls
- 14.3. Summary
-
14.1. Binding Windows Form Controls to Entities with Object Data Sources
-
15. Using the Entity Framework as a Data Source
- 15.1. Creating an ADO.NET Data Services Data Source
- 15.2. Consuming ADO.NET Data Services with the .NET 3.5 Client Library
- 15.3. Consuming ADO.NET Data Services with the AJAX Client Library
- 15.4. Summary
-
12. Taking Advantage of Object Services and LINQ to Entities
Product information
- Title: Professional ADO.NET 3.5 with LINQ and the Entity Framework
- Author(s):
- Release date: February 2009
- Publisher(s): Wrox
- ISBN: 9780470182611
You might also like
book
Entity Framework 4 in Action
Entity Framework 4 in Action is an example-rich tutorial for .NET developers with full coverage of …
book
Beginning Entity Framework Core 5: From Novice to Professional
Use the code-driven approach of Entity Framework Core 5 to build a functional web application that …
book
LINQ to Objects Using C# 4.0
“For several years, Troy has been one of the key figures in the LINQ community. This …
book
Microsoft ADO.NET Entity Framework Step by Step
Your hands-on guide to Entity Framework fundamentals Expand your expertise—and teach yourself the fundamentals of the …