Professional ADO.NET 3.5 with LINQ and the Entity Framework

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, creating EntitySetS 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 use Group By with aggregate queries, conduct the equivalent of left outer joins, and take advantage of the Contains() SQO to emulate SQL's IN() 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, instantiate DataContext 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 and DataContext objects and features, followed by a description of the DataSetExtensions. Next comes querying untyped and typed DataSets, creating lookup lists, and generating LinqDataViewS for databinding with the AsDataView() method. This ends with a tutorial that shows you how to copy LINQ query results to DataTableS.

  • "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, and ObjectStateManager. 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 support INSERT, UPDATE, DELETE and ...

Table of contents

  1. Copyright
  2. About the Author
  3. Credits
  4. Acknowledgments
  5. Introduction
    1. Who This Book Is For
    2. What This Book Covers
    3. How This Book Is Structured
      1. Part I: Getting a Grip on ADO.NET 3.5
      2. Part II: Introducing Language Integrated Query
      3. Part III: Applying Domain-Specific LINQ Implementations
      4. Part IV: Introducing the ADO.NET Entity Framework
      5. Part V: Implementing the ADO.NET Entity Framework
    4. Conventions
    5. Source Code
    6. Errata
    7. p2p.wrox.com
  6. I. Getting a Grip on ADO.NET 3.5
    1. 1. Taking a New Approach to Data Access in ADO.NET 3.5
      1. 1.1. Language Integrated Query (LINQ)
        1. 1.1.1. LINQ to Objects
          1. 1.1.1.1. Sample LINQ Queries
          2. 1.1.1.2. LINQ Data Binding with the ToList() Operator
        2. 1.1.2. LINQ to SQL
          1. 1.1.2.1. Mapping Tables to Entities with the LINQ to SQL OR Designer
          2. 1.1.2.2. Examining the Generated Classes
          3. 1.1.2.3. Binding Data-Enabled Controls to Entity Data Sources
        3. 1.1.3. Programming the DataContext
          1. 1.1.3.1. Emulating Joins by Navigating Associations
          2. 1.1.3.2. Loading Child Objects Lazily or Eagerly
          3. 1.1.3.3. Creating Explicit Joins with LINQ Join ... On Expressions
          4. 1.1.3.4. Applying Operators to Emulate SQL Functions, Modifiers, and Operators
          5. 1.1.3.5. Updating Table Data
          6. 1.1.3.6. Generating a SQL Server Database with the OR Designer
          7. 1.1.3.7. LinqDataSource Control
        4. 1.1.4. LINQ to DataSets
          1. 1.1.4.1. Joining DataSets
            1. 1.1.4.1.1. Strongly Typed Data Sets
            2. 1.1.4.1.2. Untyped Data Sets
          2. 1.1.4.2. Navigating Entity Set Associations
        5. 1.1.5. LINQ to Entities
        6. 1.1.6. LINQ to XML
          1. 1.1.6.1. LINQ to XML's Objects
          2. 1.1.6.2. Querying XML Documents
          3. 1.1.6.3. Transforming or Creating XML Documents
        7. 1.1.7. LINQ to XSD
      2. 1.2. The ADO.NET Entity Framework and Entity Data Model
        1. 1.2.1. Mapping from the Physical to the Conceptual Schema
        2. 1.2.2. Creating the Default EDM with the Entity Data Model Wizard
        3. 1.2.3. Modifying Storage to Conceptual Mapping with the EDM Designer
        4. 1.2.4. Creating and Binding to a Data Source from a Data Model
        5. 1.2.5. Materializing an Object Context
      3. 1.3. Summary
  7. II. Introducing Language Integrated Query
    1. 2. Understanding LINQ Architecture and Implementation
      1. 2.1. Namespaces That Support LINQ in .NET Fx 3.5
      2. 2.2. C# and VB Extensions to Support LINQ
        1. 2.2.1. Implicitly Typed Local Variables
        2. 2.2.2. Object Initializers
        3. 2.2.3. Array Initializers with Object Initializers
        4. 2.2.4. Collection Initializers
        5. 2.2.5. Anonymous Types
        6. 2.2.6. Extension Methods
        7. 2.2.7. Anonymous Methods and Generic Predicates
        8. 2.2.8. Lambda Expressions
          1. 2.2.8.1. C# 3.0 Lambda Expressions
          2. 2.2.8.2. VB 9.0 Lambda Expressions
        9. 2.2.9. Standard Query Operators
          1. 2.2.9.1. C# 3.0 Query Expressions
          2. 2.2.9.2. Lazy and Eager Evaluation
          3. 2.2.9.3. VB 9.0 Query Expressions
        10. 2.2.10. Expression Trees and Compiled Queries
          1. 2.2.10.1. C# 3.0 Expression Trees
          2. 2.2.10.2. VS 2008 SP1's ExpressionTreeVisualizer
          3. 2.2.10.3. VB 9.0 Expression Trees
          4. 2.2.10.4. Compiled Queries
        11. 2.2.11. The IQueryable<T> Interface and Domain-Specific LINQ Implementations
      3. 2.3. Summary
    2. 3. Executing LINQ Query Expressions with LINQ to Objects
      1. 3.1. Standard Query Operators by Group
      2. 3.2. SQOs as Keywords in C# 3.0 and VB 9.0
      3. 3.3. The LINQ Project Sample Query Explorers
      4. 3.4. Sample Classes for LINQ to Objects Code Examples
        1. 3.4.1. C# Class Definition and Initialization Code Example
        2. 3.4.2. VB Class Definition and Initialization Code Example
      5. 3.5. Restriction Operator: Where
        1. 3.5.1. Simple Where Expressions
        2. 3.5.2. Compound Where Expressions
        3. 3.5.3. Method Calls with Index Arguments and Use of IndexOf()
      6. 3.6. Projection Operators
        1. 3.6.1. Select
          1. 3.6.1.1. Simple Select Projection Expression
          2. 3.6.1.2. Multiple Select Projection Expression with Index Value
          3. 3.6.1.3. Index Value Expressions with the Let Keyword
        2. 3.6.2. SelectMany
          1. 3.6.2.1. Basic SelectMany Implementation for Associated Objects
          2. 3.6.2.2. SelectMany Overload for Equi-Joins of Associated Objects
      7. 3.7. Partitioning Operators
        1. 3.7.1. Take
        2. 3.7.2. Skip
        3. 3.7.3. Skip/Take Example
        4. 3.7.4. TakeWhile
        5. 3.7.5. SkipWhile
        6. 3.7.6. SkipWhile/TakeWhile Example
      8. 3.8. Join Operators
        1. 3.8.1. Join
        2. 3.8.2. GroupJoin
      9. 3.9. Concatenation Operator: Concat
      10. 3.10. Ordering Operators
        1. 3.10.1. OrderByDescending
        2. 3.10.2. ThenBy
        3. 3.10.3. ThenByDescending
        4. 3.10.4. Reverse
        5. 3.10.5. Ordering Operator Examples
      11. 3.11. Grouping Operator: GroupBy
        1. 3.11.1. GroupBy with Method Call Syntax
        2. 3.11.2. GroupBy with Query Expression Syntax
      12. 3.12. Set Operators
        1. 3.12.1. Distinct
        2. 3.12.2. Union
        3. 3.12.3. Intersect
        4. 3.12.4. Except
      13. 3.13. Conversion operators
        1. 3.13.1. AsEnumerable
        2. 3.13.2. AsQueryable
        3. 3.13.3. Cast
        4. 3.13.4. OfType
        5. 3.13.5. To ... Operators
          1. 3.13.5.1. ToArray
          2. 3.13.5.2. ToList
          3. 3.13.5.3. To Dictionary
          4. 3.13.5.4. ToLookup
      14. 3.14. Equality Operator: SequenceEqual
      15. 3.15. Element operators
        1. 3.15.1. First, FirstOrDefault
        2. 3.15.2. Last, LastOrDefault
        3. 3.15.3. Single, SingleOrDefault
        4. 3.15.4. DefaultIfEmpty
        5. 3.15.5. ElementAt, ElementAtOrDefault
      16. 3.16. Generation Operators
        1. 3.16.1. Range
        2. 3.16.2. Repeat
        3. 3.16.3. Empty
      17. 3.17. Quantifier Operators
        1. 3.17.1. Any
        2. 3.17.2. All
        3. 3.17.3. Contains
      18. 3.18. Aggregate Operators
        1. 3.18.1. Count and LongCount
        2. 3.18.2. Min, Max, Sum, and Average
        3. 3.18.3. Aggregate
      19. 3.19. Summary
    3. 4. Working with Advanced Query Operators and Expressions
      1. 4.1. Exploring Basic Query Syntax for Aggregate Operators
        1. 4.1.1. Basic Method Call Syntax with Numerical Operators
        2. 4.1.2. Expression Syntax with Let as a Temporary Local Aggregate Variable
          1. 4.1.2.1. Using a Lambda Function for Aggregation of Child Entity Values
          2. 4.1.2.2. Using Visual Basic's Aggregate... Into Keywords
        3. 4.1.3. Formatting the Query Output
      2. 4.2. Using Group By with Aggregate Queries
        1. 4.2.1. Grouping with Associated Child Objects
          1. 4.2.1.1. Using the Aggregate Keyword and Into Expression with VB
          2. 4.2.1.2. Using C# Group By Expression Syntax
        2. 4.2.2. Grouping with Joined Child Objects
        3. 4.2.3. Combining Join and Group By Operations with Hierarchical Group Join Expressions
        4. 4.2.4. Comparing Group Joins with Nested LINQ Queries
        5. 4.2.5. Emulating Left Outer Joins with Entity Associations
      3. 4.3. Taking Full Advantage of the Contains() SQO
        1. 4.3.1. Emulating SQL Where Clauses with Compound OR Operators
        2. 4.3.2. Emulating the SQL IN() Function with Contains()
      4. 4.4. Compiling Query Expression Trees to Improve Performance
      5. 4.5. Mocking Collections for Testing LINQ to SQL and LINQ to Entities Projects
        1. 4.5.1. Creating Mock Object Classes and Initializers
        2. 4.5.2. Creating Object Graphs with GroupJoin Expressions
      6. 4.6. Summary
  8. III. Applying Domain-Specific LINQ Implementations
    1. 5. Using LINQ to SQL and the LinqDataSource
      1. 5.1. Object/Relational Mapping with LINQ to SQL
        1. 5.1.1. Mapping Tables to Entity Sets with the LINQ to SQL O/R Designer
        2. 5.1.2. Generating Partial Entity Classes and Mapping Files with SqlMetal.exe
        3. 5.1.3. Working with *.dbml and *.xml Mapping Files
          1. 5.1.3.1. Editing *.dbml Files in the Designer
          2. 5.1.3.2. Editing *.xml Mapping Files in an XML Editor
        4. 5.1.4. Examining the Generated Classes
        5. 5.1.5. Instantiating the DataContext and Its Object Graph
      2. 5.2. Using LINQ to SQL as a Data Access Layer
        1. 5.2.1. The LINQ to SQL Query Pipeline
        2. 5.2.2. Adding, Updating, and Removing Objects
        3. 5.2.3. Detecting and Resolving Concurrency Conflicts
        4. 5.2.4. Substituting Stored Procedures for Dynamic SQL
          1. 5.2.4.1. Using a SELECT Stored Procedure to Return an ISingleResult<TEntity>
          2. 5.2.4.2. Using INSERT, UPDATE, and DELETE Stored Procedures
        5. 5.2.5. Moving the LINQ to SQL Layer to a Middle Tier
      3. 5.3. ASP.NET Databinding with the LinqDataSource Control
        1. 5.3.1. Adding a LinqDataSource to a Page
        2. 5.3.2. Substituting EntityRef for ForeignKey Values in Databound Web Controls
        3. 5.3.3. Eager-Loading EntityRef Values to Reduce Database Server Traffic
      4. 5.4. Databinding Windows Form Controls to Entities
        1. 5.4.1. Autogenerating the Obligatory Hierarchical Data Editing Form
        2. 5.4.2. Persisting Entity Edits and Collection Modifications
          1. 5.4.2.1. Adding Members to a Collection with a Surrogate, Autoincrementing Primary Key
          2. 5.4.2.2. Deleting Members with a Dependent EntitySet from a Collection
            1. 5.4.2.2.1. Specifying SQL Server Cascading Deletions
            2. 5.4.2.2.2. Adding the DeleteOnNull Attribute for Value-Type Association Keys
            3. 5.4.2.2.3. Deleting Dependent Records with UserDeletingRows Event Handlers
      5. 5.5. Summary
    2. 6. Querying DataTables with LINQ to DataSet
      1. 6.1. Comparing DataSets and DataContexts
      2. 6.2. Exploring LINQ to DataSet Features
      3. 6.3. Running Read-Only LINQ to DataSet Queries
        1. 6.3.1. Querying Untyped DataSets
        2. 6.3.2. Customizing Lookup Lists
        3. 6.3.3. Querying Typed DataSets
      4. 6.4. Creating LinqDataViews for DataBinding with AsDataView()
      5. 6.5. Copying LINQ Query Results to DataTables
        1. 6.5.1. Copying Typed DataRows
        2. 6.5.2. Processing Anonymous Types from Projections
      6. 6.6. Summary
    3. 7. Manipulating Documents with LINQ to XML
      1. 7.1. Integrating XML into the CLR
        1. 7.1.1. Minimizing XML/Object Mismatch with Xen
        2. 7.1.2. Querying XML with Cω
      2. 7.2. The System.Xml.Linq Namespace
      3. 7.3. Querying Basic XML Infosets
        1. 7.3.1. Inferring a Schema and Enabling IntelliSense for VB Queries
        2. 7.3.2. Taking Advantage of VB 9.0 Axis Properties
        3. 7.3.3. Implicit versus Explicit Typing of Element and Attribute Content
      4. 7.4. Composing XML Infosets
        1. 7.4.1. Using Functional Construction with C# 3.0
        2. 7.4.2. Using Literal XML Construction with VB 9.0
      5. 7.5. Grouping Elements and Aggregating Numeric Values of Business Documents
        1. 7.5.1. Using GroupJoin to Produce Hierarchical Documents
        2. 7.5.2. Taking Advantage of 1:Many and Many:1 Associations
        3. 7.5.3. Aggregating Order_Details and Orders Subtotals per Customer
      6. 7.6. Working with XML Namespaces and Local Names
        1. 7.6.1. XML Namespaces in C# 3.0
          1. 7.6.1.1. Namespaces in C# LINQ to XML Queries
          2. 7.6.1.2. Removing Expanded Namespaces from C# Queries
          3. 7.6.1.3. Functionally Constructing C# XDocuments with Multiple Namespaces
        2. 7.6.2. XML Namespaces in VB 9.0
          1. 7.6.2.1. Enabling IntelliSense for Namespaces
          2. 7.6.2.2. Multiple Namespaces in XML Literal Queries
          3. 7.6.2.3. Transforming Documents That Have Multiple Namespaces, with Literal XML Code
      7. 7.7. Performing Heterogeneous Joins and Lookup Operations
        1. 7.7.1. Using Lookup Operations to Add Child Element Groups
        2. 7.7.2. Joining Documents to Insert Elements
        3. 7.7.3. Joining Documents and LINQ to SQL or LINQ to Object Entities
      8. 7.8. Summary
    4. 8. Exploring Third-Party and Emerging LINQ Implementations
      1. 8.1. Emerging Microsoft LINQ Implementations
        1. 8.1.1. Parallel LINQ
          1. 8.1.1.1. Programming with PLINQ
          2. 8.1.1.2. Processing Queries
          3. 8.1.1.3. Running the PLINQ Samples
            1. 8.1.1.3.1. LINQRayTracer
            2. 8.1.1.3.2. VB and C# Samples
        2. 8.1.2. LINQ to REST
          1. 8.1.2.1. Adopting URIs as a Query Language
          2. 8.1.2.2. Running the Sample Northwind.svc WCF Service and Client Projects
            1. 8.1.2.2.1. Experimenting with URI Query Syntax
            2. 8.1.2.2.2. Query Options
            3. 8.1.2.2.3. Logical, Arithmetic and Grouping Query Operators
            4. 8.1.2.2.4. String, Date, Math, and Type Query Functions
          3. 8.1.2.3. Processing Services Requests with the NwindServicesClient
            1. 8.1.2.3.1. Executing URI Queries
            2. 8.1.2.3.2. Executing LINQ to REST Queries
            3. 8.1.2.3.3. Preventing HTTP 400 — Bad Request Errors and Lazy Loading Associated Entities
        3. 8.1.3. LINQ to XSD
          1. 8.1.3.1. LINQ to XSD's History
        4. 8.1.4. LINQ to Stored XML
      2. 8.2. Third-Party Domain-Specific LINQ Implementations
        1. 8.2.1.
          1. 8.2.1.1. LINQ to Active Directory
          2. 8.2.1.2. LINQ to SharePoint
            1. 8.2.1.2.1. Installing LINQ to SharePoint Assemblies
            2. 8.2.1.2.2. Installing the SharePoint 3.0 SDK to Support SMPL
            3. 8.2.1.2.3. Creating a Sample LINQ to SharePoint Project
            4. 8.2.1.2.4. Writing LINQ to SharePoint Query Code
            5. 8.2.1.2.5. Translating Query Expressions to Method Calls and CAML
      3. 8.3. Summary
  9. IV. Introducing the ADO.NET Entity Framework
    1. 9. Raising the Level of Data Abstraction with the Entity Data Model
      1. 9.1. Understanding the Entity-Relationship Model
        1. 9.1.1. Entity-Relationship and EDM Terminology
        2. 9.1.2. Entity-Relationship Diagrams
      2. 9.2. Comprehending Entity Framework Architecture and Components
        1. 9.2.1. Mapping from the Physical to the Conceptual Layer with the EDM Designer
          1. 9.2.1.1. Creating the XML Mapping Files and Object Layer Class File with the EDM Wizard
          2. 9.2.1.2. Adding, Updating, and Deleting the Model's Objects
          3. 9.2.1.3. Editing EntityType and AssociationSet Properties
        2. 9.2.2. Analyzing the ModelName.edmx File's Sections
          1. 9.2.2.1. Scanning the StorageModels Group
          2. 9.2.2.2. Examining the ConceptualModels Group
          3. 9.2.2.3. Tracing the Mappings Group
      3. 9.3. Working with the Entity Client, Entity SQL and Client Views
        1. 9.3.1. Writing EntityQueries in Entity SQL
        2. 9.3.2. Executing Entity SQL Queries as Client Views
      4. 9.4. Taking Advantage of Object Services
        1. 9.4.1. Working with ObjectContext
          1. 9.4.1.1. Creating an Object Context and ObjectQuery
          2. 9.4.1.2. MetadataWorkspace
          3. 9.4.1.3. ObjectStateManager
        2. 9.4.2. Writing ObjectQueries with Entity SQL
        3. 9.4.3. Composing ObjectQueries with Query Builder Methods
        4. 9.4.4. Using the LINQ to Entities Provider
      5. 9.5. Understanding the Persistence Ignorance Controversy
      6. 9.6. Summary
    2. 10. Defining Storage, Conceptual, and Mapping Layers
      1. 10.1. Exploring and Customizing the EDMX File
        1. 10.1.1. Storage Models (SSDL Content)
          1. 10.1.1.1. The EntityContainer Subgroup
            1. 10.1.1.1.1. EntitySet Elements or Subgroups
            2. 10.1.1.1.2. AssociationSet Elements or Subgroups
            3. 10.1.1.1.3. The EntityContainer Subgroup for Categories, Products, and Suppliers
          2. 10.1.1.2. EntityType Subgroups
            1. 10.1.1.2.1. Key Subgroup
            2. 10.1.1.2.2. Property Subelement
          3. 10.1.1.3. The Product EntityType Subgroup
          4. 10.1.1.4. Function Subelements and Subgroups
            1. 10.1.1.4.1. Function Definitions for a DateTime Scalar Function and Product Stored Procedures
            2. 10.1.1.4.2. Function Imports to Assign Data Retrieval Stored Procedures to an EntitySet
            3. 10.1.1.4.3. Insert, Update, and Delete Function Mapping to EntityTypes
            4. 10.1.1.4.4. Update Stored Procedure Association Mapping in the Designer
          5. 10.1.1.5. Association Subgroups
            1. 10.1.1.5.1. Population of Associations with Stored Procedures
        2. 10.1.2. Conceptual Models (CSDL Content)
          1. 10.1.2.1. The EntityContainer Subgroup
          2. 10.1.2.2. The EntityType Subgroup
          3. 10.1.2.3. The Association Subgroup
        3. 10.1.3. Mapping (MSL Content)
          1. 10.1.3.1. The EntitySetMapping Subgroup
          2. 10.1.3.2. The AssociationSetMapping Subgroup
          3. 10.1.3.3. The FunctionImportMapping Element
      2. 10.2. Implementing Table-per-Hierarchy Inheritance
        1. 10.2.1. Specifying the Discriminator Column and Creating a Derived Class
        2. 10.2.2. Querying Base and Derived Classes
          1. 10.2.2.1. Incorrect Results from is, Is, TypeOf, and OfType() Operators
          2. 10.2.2.2. Type Discrimination in Entity SQL Queries
          3. 10.2.2.3. Disambiguate Derived Object Types with an Abstract Base Type
      3. 10.3. Traversing the MetadataWorkspace
      4. 10.4. Summary
    3. 11. Introducing Entity SQL
      1. 11.1. Using the eSqlBlast Entity SQL Query Utility
        1. 11.1.1. Connection Page
        2. 11.1.2. Model Page
        3. 11.1.3. Query Page
        4. 11.1.4. Result Page
      2. 11.2. Understanding How Entity SQL Differs from Transact-SQL
        1. 11.2.1. Entity Alias Prefixes Are Mandatory
        2. 11.2.2. Explicit Projections Are Required
        3. 11.2.3. The VALUE Modifier Flattens Results
        4. 11.2.4. Dot-Notation Syntax Returns Many:One Navigation Properties
        5. 11.2.5. Nested Queries Are Required for One:Many Navigation Properties
        6. 11.2.6. JOINs Are the Last Resort
        7. 11.2.7. NAVIGATE is a Complex Substitute for Dot Notation or Nested Queries
        8. 11.2.8. REF, DEREF, CREATEREF, ROW, and KEY Manage Entity References
        9. 11.2.9. Type Constructors Create ROWs, Multisets, and Instances of EntityTypes
        10. 11.2.10. The UNION, INTERSECT, OVERLAPS, and EXCEPT Set Operators Require Sub-Queries
        11. 11.2.11. Sorting Collections Returned by Set Operators Requires a Nested Query
        12. 11.2.12. Set Operators ANYELEMENT and FLATTEN Work on Collections
        13. 11.2.13. SKIP and LIMIT Sub-Clauses of the ORDER BY Clause Handle Paging
        14. 11.2.14. IS OF, OFTYPE, and TREAT Are Type Operators for Polymorphic Queries
        15. 11.2.15. Subqueries That Return Aggregate Values for WHERE Clause Constraints Throw Exceptions
      3. 11.3. Executing eSQL Queries against the EntityClient
        1. 11.3.1. Parsing the IExtendedDataRecord from an EntityDataReader
        2. 11.3.2. Measuring the Performance Penalty of EntitySQL Queries
        3. 11.3.3. Executing Parameterized eSQL Queries
      4. 11.4. Using SQL Server Compact as an Entity Framework Data Store
        1. 11.4.1. Substituting SSCE for SQL Server [Express] as a Data Store
      5. 11.5. Summary
  10. V. Implementing the ADO.NET Entity Framework
    1. 12. Taking Advantage of Object Services and LINQ to Entities
      1. 12.1. Exploring the Generated Entity Classes
        1. 12.1.1. ModelNameEntities Partial Classes
        2. 12.1.2. EntityName Partial Classes
        3. 12.1.3. Entity Class Serialization
          1. 12.1.3.1. Serialization with Deferred-Loaded Associated Entities
          2. 12.1.3.2. Serialization with Eager-Loaded Associated Entities
      2. 12.2. Executing eSQL ObjectQueries
      3. 12.3. Enabling Deferred or Eager Loading of Associated Entities
        1. 12.3.1. Deferred Loading with the Load() Method
        2. 12.3.2. Eager Loading with Include() Operators
      4. 12.4. Ordering and Filtering Associated EntityCollections during Loading
      5. 12.5. Composing Query Builder Methods to Write ObjectQueries
      6. 12.6. Writing LINQ to Entities Queries
        1. 12.6.1. Unsupported LINQ Keywords, Standard Query Operators, and Overloads
        2. 12.6.2. Conventional LINQ to Entities Queries
        3. 12.6.3. Using the Include() Operator with LINQ to Entities Queries
        4. 12.6.4. Compiling LINQ to Entity Queries
        5. 12.6.5. Comparing the Performance of LINQ to Entities Queries
      7. 12.7. Parameterizing Object Queries
      8. 12.8. Summary
    2. 13. Updating Entities and Complex Types
      1. 13.1. Understanding the ObjectContext's ObjectStateManager and Its Children
      2. 13.2. Updating or Deleting Entities
        1. 13.2.1. Persisting Changes to the Data Store
        2. 13.2.2. Logging Entities' State
        3. 13.2.3. Deleting Selected Entities
        4. 13.2.4. Updating Associated EntitySets or EntityObjects
        5. 13.2.5. Deleting Entities with Dependent Associated Entities
        6. 13.2.6. Transacting Updates and Deletions
      3. 13.3. Adding Entities
      4. 13.4. Refreshing Stale Entities
      5. 13.5. Validating Data Additions and Updates
      6. 13.6. Optimizing the ObjectContext Lifetime
      7. 13.7. Comparing the Performance of LINQ to Entities and Out-of-Band SQL Updates
      8. 13.8. Managing Optimistic Concurrency Conflicts
        1. 13.8.1. Enabling Optimistic Concurrency Management for Entity Properties
        2. 13.8.2. Implementing Optimistic Concurrency Management with Code
      9. 13.9. Performing CRUD Operations with Stored Procedures
        1. 13.9.1. Creating the Initial Data Model
        2. 13.9.2. Adding FunctionImports to Populate the EntitySets
        3. 13.9.3. Assigning Insert, Update and Delete Stored Procedures to Entities
          1. 13.9.3.1. Using a Stored Procedure to Insert a New Entity Instance
          2. 13.9.3.2. Updating an Entity Instance and Managing Concurrency with Original Values
          3. 13.9.3.3. Updating an Entity Instance and Managing Concurrency with a Timestamp Property
          4. 13.9.3.4. Deleting Entity Instances with Stored Procedures
      10. 13.10. Working with Complex Types
        1. 13.10.1. Modeling a Complex Type
          1. 13.10.1.1. Modifying the CSDL Section
          2. 13.10.1.2. Modifying the MSL Section
          3. 13.10.1.3. Reusing a ComplexType Definition
      11. 13.11. Summary
    3. 14. Binding Entities to Data-Aware Controls
      1. 14.1. Binding Windows Form Controls to Entities with Object Data Sources
        1. 14.1.1. Using the Load(), Include(), and Attach() Methods for Shaping Object Graphs
          1. 14.1.1.1. Deferred Loading of Associated Objects with the Load() Method
          2. 14.1.1.2. Eager Loading of Multiple Associated Objects with the Include() Method
          3. 14.1.1.3. Deferred Loading of Associated Objects with the Attach() Method
        2. 14.1.2. Selecting the Active Top-Level and Associated Entity Instances
        3. 14.1.3. Using Unbound ComboBoxes to Specify Associations
          1. 14.1.3.1. Adding Event Handlers for ComboBoxColumns
          2. 14.1.3.2. Updating Association Sets with the SelectedIndexChanged Event Handler
        4. 14.1.4. Setting Composite Primary-Key Members with Combo Boxes
          1. 14.1.4.1. Detecting Attempts to Change Composite Primary-Key Values
          2. 14.1.4.2. Enforcing Object Deletion and Addition Operations for Updates
          3. 14.1.4.3. Selecting and Adding a New EntityObject and AssociationSets
        5. 14.1.5. Persisting Changes to the Data Store
      2. 14.2. Using the EntityDataSource with ASP.NET Server Controls
        1. 14.2.1. Adding an EntityDataSource Control to an ASP.NET Web Application Page
        2. 14.2.2. Exploring the Entity Datasource
          1. 14.2.2.1. EntityDataSource Properties
          2. 14.2.2.2. Where and Group By Clauses
          3. 14.2.2.3. EntityDataSource Events
        3. 14.2.3. Binding and Formatting a GridView Control
        4. 14.2.4. Using the GroupBy Property and a Drop-Down List to Display Customers by Country
        5. 14.2.5. Adding a Linked DetailsView
      3. 14.3. Summary
    4. 15. Using the Entity Framework as a Data Source
      1. 15.1. Creating an ADO.NET Data Services Data Source
        1. 15.1.1. Understanding REST Architecture
        2. 15.1.2. Creating a Simple Web Service and Consuming It in a Browser
        3. 15.1.3. Navigating Collections and their Members
        4. 15.1.4. Taking Advantage of Query String Options
        5. 15.1.5. Invoking Service Operations
      2. 15.2. Consuming ADO.NET Data Services with the .NET 3.5 Client Library
        1. 15.2.1. Executing Queries from Windows Form Clients
          1. 15.2.1.1. Executing a Query-String URI from a Client
          2. 15.2.1.2. Executing a DataServiceQuery
          3. 15.2.1.3. Executing LINQ to REST Queries
          4. 15.2.1.4. Returning Associated Entities
          5. 15.2.1.5. Executing Batch Queries with DataServiceRequests
        2. 15.2.2. Changing EntitySets with URI Queries and DataService.SaveChanges()
          1. 15.2.2.1. Adding New Entities
          2. 15.2.2.2. Updating Entities
          3. 15.2.2.3. Deleting Entities
          4. 15.2.2.4. Managing Optimistic Concurrency Conflicts
          5. 15.2.2.5. Batching Changes
      3. 15.3. Consuming ADO.NET Data Services with the AJAX Client Library
        1. 15.3.1. Becoming Familiar with JavaScript Object Notation
        2. 15.3.2. Creating an AJAX Test Client for Astoria
        3. 15.3.3. Adding, Editing, and Removing Entities
      4. 15.4. Summary

Product information

  • Title: Professional ADO.NET 3.5 with LINQ and the Entity Framework
  • Author(s): Roger Jennings
  • Release date: February 2009
  • Publisher(s): Wrox
  • ISBN: 9780470182611