Index  

Description

Outline


Linq/C# 3.0 MiniCamp  

Duration: 1-day (Lecture-Only) to 3-days (with Hands-On Labs).

Inquire about an on-site presentation of this course.


Course Description  

Linq is a technology – being added to the .NET Framework – that will change your programming life. Linq is designed to seamlessly integrate data query features into programming languages like C#, eliminating the disconnection between traditional programming languages on the one hand, and query technologies like SQL and XQuery on the other. But Linq doesn’t just let you access data in databases or structured documents: you can use it to query data from virtually any data source – including .NET collections and sequences that implement IEnumerable<T>. And Linq goes further by letting you build, manage and express queries as objects which adhere to contemporary OO principles. And while a shallow appraisal of Linq may make you think it’s only for data access, you can actually apply it to any tier of your application, from client to middle-tier, as well as the data-access layer.

 

In this subset of our 5-day LINQ/.NET 3.5 BootCamp, you’ll get an outstanding exposure to the fundamentals of Linq and C# 3.0.

 

We’ll start by jumping right into building Linq queries: Selecting, Filtering, Ordering and Grouping. With these and more powerful queries (joining, sub-selects and data transformations), you’ll quickly get the idea of how to use Linq using C# 3.0. We’ll also discuss how Linq queries – based on the custom iterators introduced with C# 2.0 – leverage deferred execution so that you don’t incur the overhead of query until you consume it. We’ll also take a quick look at output options: how to emit query results as XML or output to a database.

 

Next, we’ll look at the role of C# 3.0, and how the new features in 3.0 evolved from 2.0. You’ll learn the new initialization techniques available, and how to “new up” anonymous types on-demand. We’ll take a detailed look at extension methods and how they’re both implicitly and explicitly used in Linq Queries, but also how you can use them in day-to-day .NET development. And we’ll delve into Lambda Expressions, a new way of creating anonymous methods, but easier to read and write. We’ll wrap up our C# 3.0 section with auto-implemented properties and partial methods.

 

The next section will let us explore how Linq is applied to real-world scenarios: querying and updating data from disparate sources like SQL databases, typed and untyped ADO.NET DataSets, and XML documents. We’ll look at lots of fine details: how to use Linq to SQL (formerly known as DLinq) to query and update multiple tables; how to use Linq with existing typed/untyped DataSets – and when you should/shouldn’t; how the VS2008 toolset will make so much of this child’s play to get work done. We’ll also examine Linq to XML, and you’ll see how you can easily use it in place of – and along side of – existing code that accesses and updates XML documents. You’ll see how you can quickly and easily serialize and de-serialize entire object graphs to and from XML documents cleanly – in a version-independent fashion – without the crud normally inserted by traditional .NET serialization.

 

Finally, we’ll wrap-up with a behind-the-scenes look: what goes on when you create query expressions, how they work, and how .NET Framework 3.5 has been extended to include an entire sub-framework of methods and classes to support Linq. We’ll also look at how you can build expressions and queries dynamically to address query needs only known at runtime.

 

Pre-requisites: to attend this course, you should have a minimum of 2+ years experience programming C# and the .NET Framework, and 1+ year programming C# 2.0, or you should have attended the .NET BootCamp. (Sorry, no hand-holding if you’re new to .NET/C#.)

 


Course Outline  

The Power of Linq Productivity

  • Linq Data Sources
    • IEnumerable<T>
      • Inferred Typing
    • IQueryable<T>
    • Data and XML sources
  • Basic Linq Queries
    • Selecting
    • Filtering
    • Ordering
    • Grouping
  • More Interesting Linq Queries
    • Joining
    • Selecting Subsets
    • Sub-Selects
    • Data Transformations
    • Adding variables to queries: let
    • Deferred vs. Immediate Execution
  • Linq Output
    • To XML
    • To a database
    • To other destinations

C# 3.0 and Linq

  • C# 2.0/.NET 2.0: A Brief Retrospective
    • Generics and Type-Safety
    • Custom Iterators: Iterators and Deferred Execution
    • Generic Delegates
    • Anonymous Methods
  • New Initialization Techniques
    • Local Variable Type Inference
    • Simpler Object initialization
    • Simpler Collection initialization
  • Types-on-demand: anonymous types
    • Extension Methods
    • Extension Methods used by Linq Queries
    • Extension Methods in everyday C#/.NET
  • Best Practices for defining Extension Methods
    Building-block methods: Lambda Expressions
    • A cleaner syntax for anonymous methods
    • The consequences of using outer variables
  • The Fun Stuff!
    • Auto-Implemented Properties
    • Partial Methods

Linq Applied

  • Linq to SQL (DLinq)
    • The Linq to SQL Model
    • Entity Classes
    • Associations and Foreign Keys
    • DataContext
    • Encapsulating and leveraging calls to Sprocs and Functions
    • Data Updates
    • Using the O/R Designer
    • Using SQLMetal
    • Best Practices: when to use Linq to SQL (and when not to)
  • Linq to DataSets
    • Recall: ADO.NET Typed/Untyped DataSets
    • Query Limitations of DataSets
    • Linq Queries on Untyped DataSets
      • Single Table Queries
      • Cross-Table Queries
    • Linq Queries on Typed DataSets
    • Comparing DataRows and Set operations
    • Creating New DataTables
    • DataSet-specific APIs
    • Best Practices: when to use Linq to DataSets (and when not to)
  • Linq to XML (XLinq)
    • Linq to XML as a light-weight wrapper over .NET XML classes
    • The XLinq DOM: XDocument, XElement, XAttribute
    • Loading, Parsing, Saving and Serializing
    • Version-independent Serialization/De-Serialization of Object Graphs
    • Constructing trees
    • Built-in Deep Copy
    • Navigation and Query
    • Updating
    • Retrieving and using Values
    • Names, namespaces and Attributes
    • Projecting and transforming

Linq Behind-the-Scenes

  • Query Expressions
    • Delegate
    • Expression Trees
    • Compiling Expression Trees
    • The AsQueryable Operator
    • The Expression “Code Dom”
    • Expression Trees
    • Lambdas as Expression
  • The Linq Framework
    • Linq Extension Methods
    • Linq Iterator Classes
  • Conclusions and Wrap-up
  • Deficiencies in traditional query technologies

*Outline details subject to change without notice.


Coming Soon  


Commentary  

Regarding .NET 2.0 / C# 2.0 BootCamp

"A great way to get a jump start in C# and Visual Studio 2005."

--Asa Andersson, KnowIT Dalarna AB