Home Page Icon
Home Page
Table of Contents for
Cover
Close
Cover
by Paolo Pialorsi and Marco Russo
Programming Microsoft® LINQ in Microsoft .NET Framework 4
Programming Microsoft® LINQ in Microsoft .NET Framework 4
Dedication
A Note Regarding Supplemental Files
Preface
Acknowledgments
Introduction
Who Is This Book For?
Organization of This Book
Conventions and Features in This Book
System Requirements
The Companion Website
Find Additional Content Online
Errata & Book Support
We Want to Hear from You
Stay in Touch
I. LINQ Foundations
1. LINQ Introduction
What Is LINQ?
Why Do We Need LINQ?
How LINQ Works
Relational Model vs. Hierarchical/Network Model
XML Manipulation
Language Integration
Declarative Programming
Type Checking
Transparency Across Different Type Systems
LINQ Implementations
LINQ to Objects
LINQ to ADO.NET
LINQ to XML
Summary
2. LINQ Syntax Fundamentals
LINQ Queries
Query Syntax
Full Query Syntax
Query Keywords
From Clause
Where Clause
Select Clause
Group and Into Clauses
Orderby Clause
Join Clause
Let Clause
Additional Visual Basic Keywords
Deferred Query Evaluation and Extension Method Resolution
Deferred Query Evaluation
Extension Method Resolution
Some Final Thoughts About LINQ Queries
Degenerate Query Expressions
Exception Handling
Summary
3. Linq to Objects
Query Operators
The Where Operator
Projection Operators
Select
SelectMany
Ordering Operators
OrderBy and OrderByDescending
ThenBy and ThenByDescending
Reverse Operator
Grouping Operators
Join Operators
Join
GroupJoin
Set Operators
Distinct
Union, Intersect, and Except
Zip
Aggregate Operators
Count and LongCount
Sum
Min and Max
Average
Aggregate
Aggregate Operators in Visual Basic
Generation Operators
Range
Repeat
Empty
Quantifier Operators
Any
All
Contains
Partitioning Operators
Take
TakeWhile
Skip and SkipWhile
Element Operators
First
FirstOrDefault
The Last and LastOrDefault
Single
SingleOrDefault
ElementAt and ElementAtOrDefault
DefaultIfEmpty
Other Operators
Concat
SequenceEqual
Conversion Operators
AsEnumerable
ToArray and ToList
ToDictionary
ToLookup
OfType and Cast
Summary
II. LINQ to Relational
4. Choosing Between LINQ to SQL and LINQ to Entities
Comparison Factors
When to Choose LINQ to Entities and the Entity Framework
When to Choose LINQ to SQL
Other Considerations
Summary
5. LINQ to SQL: Querying Data
Entities in LINQ to SQL
External Mapping
Data Modeling
DataContext
Entity Classes
Entity Inheritance
Unique Object Identity
Entity Constraints
Associations Between Entities
EntityRef
EntitySet
Graph Consistency
Relational Model vs. Hierarchical Model
Data Querying
Projections
Stored Procedures and User-Defined Functions
Stored Procedures
User-Defined Functions
Compiled Queries
Different Approaches to Querying Data
Direct Queries
Deferred Loading of Entities
Deferred Loading of Properties
Read-Only DataContext Access
Limitations of LINQ to SQL
Aggregate Operators
Partitioning Operators
Element Operators
String Methods
DateTime Methods
LIKE Operator
Unsupported SQL Functionalities
Thinking in LINQ to SQL
The IN/EXISTS Clause
SQL Query Reduction
Mixing .NET Code with SQL Queries
Summary
6. LINQ to SQL: Managing Data
CRUD and CUD Operations
Entity Updates
Cascading Deletes and Updates
Entity States
Entity Synchronization
Database Updates
Overriding SubmitChanges
Customizing Insert, Update, and Delete
Stored Procedures
Intercepting Insert, Update, and Delete Operations
Database Interaction
Concurrent Operations
Column Attributes for Concurrency Control
Transactions
Exceptions
DataContext Construction
Database Reads
Database Writes
Entity Manipulation
Databases and Entities
Entity Attributes to Maintain Valid Relationships
Deriving Entity Classes
Attaching Entities
Entity Serialization
Attach Operation
Binding Metadata
External XML Mapping File
Creating a Database from Entities
Creating Entities from a Database
Differences Between the .NET Framework and SQL Type Systems
Summary
7. LINQ to SQL: Modeling Data and Tools
File Types
DBML—Database Markup Language
C# and Visual Basic Source Code
XML—External Mapping File
LINQ to SQL File Generation
Generating a DBML File from an Existing Database
Generating an Entity’s Source Code with Attribute-Based Mapping
Generating an Entity’s Source Code with an External XML Mapping File
Creating a DBML File from Scratch
SQLMetal
Generating a DBML File from a Database
Generating Source Code and a Mapping File from a Database
Generating Source Code and a Mapping File from a DBML File
Using the Object Relational Designer
DataContext Properties
Entity Class
Entity Members
Association Between Entities
One-to-One Relationships
Entity Inheritance
Stored Procedures and User-Defined Functions
Return Type of Data Function
Mapping to Delete, Insert, and Update Operations
Views and Schema Support
Summary
8. LINQ to Entities: Modeling Data with Entity Framework
The Entity Data Model
Generating a Model from an Existing Database
Starting from an Empty Model
Generated Code
Entity Data Model (.edmx) Files
Associations and Foreign Keys
Complex Types
Inheritance and Conditional Mapping
Modeling Stored Procedures
Non-CUD Stored Procedures
CUD Stored Procedures
POCO Support
T4 Templates
Summary
9. LINQ to Entities: Querying Data
EntityClient Managed Providers
LINQ to Entities
Selecting Single Entities
Unsupported Methods and Keywords
Canonical and Database Functions
User-Defined Functions
Stored Procedures
ObjectQuery<T> and ObjectContext
Lazy Loading
Include
Load and IsLoaded
The LoadProperty Method
MergeOption
The ToTraceString Method
ExecuteStoreCommand and ExecuteStoreQuery
The Translate<T> Method
Query Performance
Pre-Build Store Views
EnablePlanCaching
Pre-Compiled Queries
Tracking vs. No Tracking
Summary
10. LINQ to Entities: Managing Data
Managing Entities
Adding a New Entity
Updating an Entity
Deleting an Entity
Using SaveChanges
Cascade Add/Update/Delete
Managing Relationships
Using ObjectStateManager and EntityState
DetectChanges and AcceptAllChanges
ChangeObjectState and ChangeRelationshipState
ObjectStateManagerChanged
EntityKey
GetObjectByKey and TryGetObjectByKey
Managing Concurrency Conflicts
Managing Transactions
Detaching, Attaching, and Serializing Entities
Detaching Entities
Attaching Entities
ApplyOriginalValues and ApplyCurrentValues
Serializing Entities
Using Self-Tracking Entities
Summary
11. LINQ to DataSet
Introducing LINQ to DataSet
Using LINQ to Load a DataSet
Loading a DataSet with LINQ to SQL
Loading Data with LINQ to DataSet
Using LINQ to Query a DataSet
Understanding DataTable.AsEnumerable
Creating DataView Instances with LINQ
Using LINQ to Query a Typed DataSet
Accessing Untyped DataSet Data
Comparing DataRow Instances
Summary
III. LINQ to XML
12. LINQ to XML: Managing the XML Infoset
Introducing LINQ to XML
LINQ to XML Programming
XDocument
XElement
XAttribute
XNode
XName and XNamespace
Other X* Classes
XStreamingElement
XObject and Annotations
Reading, Traversing, and Modifying XML
Summary
13. LINQ to XML: Querying Nodes
Querying XML
Attribute, Attributes
Element, Elements
XPath Axes “Like” Extension Methods
XNode Selection Methods
InDocumentOrder
Understanding Deferred Query Evaluation
Using LINQ Queries over XML
Querying XML Efficiently to Build Entities
Transforming XML with LINQ to XML
Support for XSD and Validation of Typed Nodes
Support for XPath and System.Xml.XPath
Securing LINQ to XML
Serializing LINQ to XML
Summary
IV. Advanced LINQ
14. Inside Expression Trees
Lambda Expressions
What Is an Expression Tree?
Creating Expression Trees
Encapsulation
Immutability and Modification
Dissecting Expression Trees
The Expression Class
Expression Tree Node Types
ExpressionType Enumeration
Classes Derived from Expression
Practical Nodes Guide
LambdaExpression and ParameterExpression
BinaryExpression
ConstantExpression
MethodCallExpression
ConditionalExpression
InvocationExpression
Visiting an Expression Tree
Dynamically Building an Expression Tree
How the Compiler Generates an Expression Tree
Combining Existing Expression Trees
Dynamic Composition of an Expression Tree
Summary
15. Extending LINQ
Custom Operators
Specialization of Existing Operators
Dangerous Practices
Limits of Specialization
Creating a Custom LINQ Provider
The IQueryable Interface
From IEnumerable to IQueryable and Back
Inside IQueryable and IQueryProvider
Writing the FlightQueryProvider
The FlightStatusService Class
Implementing IQueryable in FlightQuery
Implementing IQueryProvider in FlightQueryProvider
Implementing an ExpressionVisitor in FlightQueryTranslator
Working with the FlightQueryProvider
Cost-Benefit Balance of a Custom LINQ Provider
Summary
16. Parallelism and Asynchronous Processing
Task Parallel Library
The Parallel.For and Parallel.ForEach Methods
The Parallel.Invoke Method
The Task Class
The Task<TResult> Class
Controlling Task Execution
Using Tasks for Asynchronous Operations
Concurrency Considerations
Race Conditions
Concurrent Collections
Task Synchronization
PLINQ
Threads Used by PLINQ
Implementing PLINQ
Consuming the Result of a PLINQ Query
Pipelined Processing
Stop-and-Go Processing
Inverted Enumeration
Controlling Result Order in PLINQ
Processing Query Results
Handling Exceptions with PLINQ
Canceling a PLINQ Query
Controlling Execution of a PLINQ Query
Changes in Data During Execution
PLINQ and Other LINQ Implementations
Reactive Extensions for .NET
Summary
17. Other LINQ Implementations
Database Access and ORM
Data Access Without a Database
LINQ to SharePoint Examples
LINQ to Services
LINQ for System Engineers
Dynamic LINQ
Other LINQ Enhancements and Tools
Summary
V. Applied LINQ
18. LINQ in a Multitier Solution
Characteristics of a Multitier Solution
LINQ to SQL in a Two-Tier Solution
LINQ in an n-Tier Solution
Using LINQ to SQL as a DAL Replacement
Abstracting LINQ to SQL with XML External Mapping
Using LINQ to SQL Through Real Abstraction
Using LINQ to XML as the Data Layer
Using LINQ to Entities as the Data Layer
LINQ in the Business Layer
Using LINQ to Objects to Write Better Code
IQueryable<T> vs. IEnumberable<T>
Identifying the Right Unit of Work
Handling Transactions
Concurrency and Thread Safety
Summary
19. LINQ Data Binding
using LINQ with ASP.NET
Using LinqDataSource
Paging Data with LinqDataSource and DataPager
Handling Data Modifications with LinqDataSource
Using Custom Selections with LinqDataSource
Using LinqDataSource with Custom Types
Using EntityDataSource
Paging Data with EntityDataSource and DataPager
Handling Data Modifications with EntityDataSource
Using Custom Selections with EntityDataSource
Binding to LINQ Queries
using LINQ with WPF
Binding Single Entities and Properties
Binding Collections of Entities
using LINQ with Silverlight
using LINQ with Windows Forms
Summary
Index
About the Authors
Copyright
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Next
Next Chapter
Programming Microsoft® LINQ in Microsoft .NET Framework 4
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset