Loading...
Professional ADO.NET 3.5 with LINQ and the Entity Framework
ISBN: 978-0-470-18261-1
January 2009
672 pages
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.
DataTable
s with LINQ to DataSets, creating EntitySet
s 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. 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. 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. 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 LinqDataView
s for databinding with the AsDataView()
method. This ends with a tutorial that shows you how to copy LINQ query results to DataTable
s. GroupJoin()
to produce hierarchical documents, and work with XML namespaces in C# and VB. 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. *.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. SELECT
queries. (eSQL v1 doesn't support INSERT
, UPDATE
, DELETE
and other SQL Data Manipulation Language constructs). You execute eSQL queries against the EntityClient
, measure the performance hit of eSQL compared to T-SQL, execute parameterize eSQL queries, and use SQL Server Compact 3.5 as a data store. C# and VB Sample projects demonstrate the programming techniques. ObjectContext
. It continues with demonstrating use of partial classes for the ModelName
Entities
and EntityName
objects, executing eSQL ObjectQuery
s, and deferred or eager loading of associated entities, including ordering and filtering the associated entities. Also covers instructions for composing QueryBuilder methods for ObjectQuery
s, LINQ to Entities queries, and parameterizing ObjectQuery
s. EntitySet
s and manage optimistic concurrency conflicts. It starts with a detailed description of the ObjectContext.ObjectStateManager
and its child objects, which perform object identification and change tracking operations with EntityKey
s. This also covers validation of create and update operations, optimizing the DataContext
lifetime, performing updates with stored procedures, and working with complex types. ObjectContext.EntitySet
instances, drag-and-drop addition of BindingNavigator
, BindingSource
, bound TextBox
, and DataGridView
controls to Windows forms. You also learn how to update EntityReference
and EntitySet
values with ComboBox
columns in DataGridView
controls. (You can’t update EntitySet
values directly; you must delete and add a new member having the required value). This concludes with a demonstration of the use of the ASP.NET EntityDataSource
control bound to GridView
and DropDownList
controls.