What you will learn in this course
This course will teach you to exploit the full capabilities of Microsoft's revolutionary platform for universal data access: Entity Framework 5.0, which is built on .NET 4.5 and compatible with Visual Studio 2012.
The Entity Framework provides a conceptual model that more closely resembles
entities and relationships in the real world and includes an industrial-strength
ORM (Object-Relational Mapping) tool that allows you connect to almost any
In this course we will cover many of the features in EF 5 that enable you to build service-oriented, n-tier applications using test-driven methodologies with robust architectural design patterns.
You'll get answers to these questions:
- When should I use LINQ instead of "classic" ADO.NET?
- How can I use stored procedures with the Entity Framework to retrieve and update relational data?
- How can I create and consume data from the Internet cloud using REST-ful data services?
- How do I build real-world n-tier applications using LINQ and the Entity Framework?
- How do I leverage EF's support for POCO's (Plain Old CLR Objects) and chose a change-tracking mechanism that is appropriate for my application design?
In this course, you learn to:
Course outline and topics
In 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.5 and Visual Studio 2012 Microsoft is releasing a new version of the Entity Framework, an enterprise-level 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 flexible architectural design patterns. You will also learn to employ WCF Data Services to integrate data from the Internet cloud.
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#: anonymous types, extension methods and lambda expressions.
LINQ to Objects
Language Integrated Query (LINQ) is a core feature of the .NET Framework and makes query data a first-class feature of the C# programming language. Now we can group, sort, and filter in-memory collections of objects. With SQL-like syntax (from, where, select, orderby, group by, etc), we can leverage an assortment of query operators to perform join, partition, conversion, and aggregation operations.
LINQ to XML
LINQ to XML provides an easy-to-use API for both reading and writing XML files. It's the successor to the 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 and from XML, while supplying a bridge to legacy API's, such as XPath and XSLT.
Entity Framework Architecture
Entity Framework 5.0 is built on top of .NET 4.5 and represents a stable and mature platform for representing relational data in a way that more closely resembles the real world. There is a built-in object-relational mapper, with a Visual Studio designer and support for stored procedures. The latest version incorporates numerous performance improvements with query pre-compilation and caching. You can stream data with a reader and dynamic SQL, perform batch updates, or use LINQ to generate entities that can be updated with changes persisted to the database.
POCO Support in the Entity Framework
We'll take a deep dive into support for POCO's (Plain Old CLR Objects) in the Entity Framework and examine when it is appropriate to use them instead of the default generated entities. You'll also learn now to exploit customizable code-generation templates using the T4 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. 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. We will also cover additional functions and operators for LINQ queries available with EF, including the scalar and table-valued functions, and the ability to execute "pass-through" queries and commands directly against the database.
"Code-First" describes an approach to developing applications with Entity Framework where the entity model is inferred by the runtime based on class definitions. No need to create (or maintain) a model using the designer. By default, EF code-first supports a "convention over configuration" approach that enables you to rely on common mapping conventions instead of having to explicitly configure mappings. But if you have an existing database and need to specify mappings, you can either place "data annotations" attributes on entity classes or use a fluent API.
In this module we will discuss best practices for WCF and Web API service-oriented applications and when it is appropriate to use custom DTO's (Data Transfer Objects). We will also cover the motivation for HTTP oriented services as an alternative to SOAP-based services. We'll examine the major tenets including the importance of URIs, HTTP methods and status codes, content negotiation and hypermedia. We'll conclude with the new client-side programming model for HTTP services with the HttpClient API
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 and when to use stored procedures versus dynamic queries. You'll learn how to configure an entity data model to use stored procedures for CRUD (Create, Retrieve, Update, Delete) operation and mappings needed to manage conflicts.
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 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.
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 REST-ful resources, 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 and expose custom data sources.
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 (DDD), such as Repository and Unit of Work.
Self Tracking Entities
Self-Tracking Entities contain logic to track changes made on a disconnected tier. This optional module shows how to track changes in any tier and then replay these changes into a context to be saved..
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.