Overview
With Visual Studio 2008 Microsoft released LINQ (Language Integrated Query), a powerful API and set of language extensions for querying and manipulating data, whether it resides in a database, an XML document or an in-memory collection. With .NET 4.0 and Visual Studio 2010 Microsoft is releasing a new version of the Entity Framework, an industrial-strength object-relational mapping technology that allows you to build a conceptual object model over any backend database - not just SQL Server.
This course will teach you to exploit the full capabilities of Microsoft's revolutionary new platform for universal data access. You will learn to build real-world n-tier applications using test-driven methodologies and robust architectural design patterns. You will also learn to employ WCF Data Services to integrate data from the Internet cloud.
Day 1
Functional Programming in C#
The C# Programming Language has evolved to include concepts borrowed from the world of functional programming. This session will start with a look at Iterators and Anonymous Methods, which were introduced in C# 2.0 and lay the groundwork for adding functional capabilities to your code. You'll also learn new features that make functional programming a first class citizen of C# 3.0: anonymous types, extension methods and lambda expressions.
LINQ to Objects
The central feature of .NET 3.5 is Language Integrated Query (LINQ), making query a first-class feature of the programming language. Now we can group, sort, and filter in-memory collections of objects. With SQL-like syntax (from, where, select, orderby, group by), we can leverage an assortment of query operators to perform join, partition, conversion, and aggregation functions.
LINQ to XML
LINQ to XML provides an easy-to-use API for both reading and writing XML files. It's the successor to DOM and XPath for navigating and searching XML documents. LINQ to XML offers an approach to XML queries that is element-centric and makes managing namespaces more straightforward. At the same time, it provides a way to perform serialization of objects to XML, while supplying a bridge to legacy API's, such as XPath and XSLT.
Day 2
Entity Framework Architecture
While LINQ to SQL is restricted for use with SQL Server 2000 or later, the Entity Framework can be used with other relational databases, and it includes a powerful mapping engine to help insulate your application from changes to the database schema. We will examine how to write queries that use LINQ to return objects or use Entity SQL to execute a data reader.
POCO Support in the Entity Framework
We'll take a deep dive into support for POCO's (Plain Old CLR Objects) in Entity Framework 4.0 and examine when it is appropriate to use them instead of the default entities generated by Entity Framework. You'll also learn now to exploit customizable code-generation templates using the T4 code generation technology built into Visual Studio. The Entity Framework also provides options for eager, explicit and lazy loading of related entities, as well as deferred versus real-time change-tracking, and you'll learn strategies for selecting which approach is best for your application.
LINQ to Entities
LINQ to Entities combines the flexibility of the Entity Framework with the power of language-integrated query, providing compile-time type-safety and syntax-checking. You'll learn how to improve performance by using compiled queries and views. We will also cover additional functions and operators for LINQ queries available with EF 4.0, including the ability to execute queries and commands directly against the database.
Day 3
N-Tier Applications
Entity Framework 4.0 ships with a code-generation template for "self-tracking entities." These are POCO classes that are ignorant of persistence concerns but which know how to track their own change state. You'll learn how to use STE's in an n-tier application, building a Data Access Layer to abstract away database operations from the rest of your application. We'll also discuss best practices for transactions and concurrency management in service-oriented applications and when custom DTO's (Data Transfer Objects) are appropriate.
Managing Connections and Transactions
In this session we'll focus on how to make EF applications production-ready. We'll discuss managing database connections and how to use transactions effectively, including setting the isolation level and when to use local versus distributed transactions.
Concurrency and Stored Procedures
Here you'll learn how to control concurrency and resolve conflicts among multiple users. We'll also cover improved support for stored procedures in EF 4.0 and when to use stored procedures versus dynamic queries. You'll also learn how to configure an entity data model to use stored procedures for CRUD (Create, Retrieve, Update, Delete) operation and how to write sprocs that will allow you to manage update conflicts among multiple users.
Day 4
Mapping Scenarios
The Entity Framework provides a great deal of flexibility for mapping entities to database tables. Here you'll learn how to customize the EF mapping files to split a table row into different entities and select alternatives for object inheritance in the database, including table-per-hierarchy, table-per-type and table-per-concrete-type. You'll also learn how to take advantage of improvements in the EDM design tools that ship with Visual Studio 2010.
Introduction to WCF Data Services
WCF Data Services combines patterns and libraries that enable any data store to be exposed as a flexible data service. These data services integrate naturally with the Web and can be consumed by Web clients within a corporate network or across the Internet. In this module you'll learn to expose data to web clients as a REST-ful resource, addressable with URIs that clients can interact with using standard HTTP verbs, such as GET and POST.
WCF Data Services Advanced Features
WCF Data Services also has a number of advanced features, which allow you to control things like how query results are merged into previously cached objects, eager-loading related entities, and performing projections using a select statement. In this session you will learn how to leverage these features for more fine-grained control and to create query interceptors which allow you to perform logging, validation, and authorization. You will also learn how to manage concurrency among multiple users and expose data services using custom data sources.
Day 5
Design Patterns and Testability Features
Application maintainability needs to be part of the design process from the beginning, which is why it pays to consider common design patterns for data-centric applications. We will examine how to use various design patterns, such as Repository and Unit of Work, and examine techniques for employing a test driven development (TDD) methodology.
Model-First and Code-First Development Approaches
This module explores a "model-first" approach to developing EF applications, which allows you to create an entity data model from scratch then generate tables based on the model. We will also take a look at creating an entity model dynamically at runtime based on class definitions, an approach called "Code-First."
Appendices
LINQ to SQL
Contrary to popular belief, LINQ to SQL is designed for real-world applications that run in a production environment. For example, LINQ to SQL allows you to use stored procedures for improved performance and security, and it supports the detection and resolution of conflicts among multiple users. You'll master these and other advanced topics, such as eager loading, object caching, identity management and change tracking. In addition, you'll learn effective transaction management and how to write partial methods for data validation.
Custom LINQ Providers
LINQ can be used to query almost any conceivable data source. All that's needed is a way to translate a query expression into some other form, such as SQL statements or even web service operations. Here you'll learn here how to map LINQ expression trees to data source specific queries in order to add a LINQ facade to just any API.