Building Effective Web Applications with ASP .Net 3.5 - Week 2

Last week I delivered part two of a six part series of webcasts for a course I created for my employer, titled "Building Effective Web Applications with ASP .Net 3.5". Each session lasts two hours. Week 2 we focused on LINQ (Language Integrated Query). LINQ is a general purpose query facility to query relational data, XML data, objects/collections that allows us to query any of these data shapes in a consistent manner. LINQ query syntax resembles SQL except that the 'from' clause is in the beginning of the query, which allows the compiler to infer the type of the object.

Here are some of the benefits of using LINQ:
  1. You may not need to build an entire DAL (data access layer)
  2. It is much easier to query XML – don’t have to use Xpath
  3. We can work with data in a consistent way – whether it is SQL Server data, XML data, ADO .Net dataset, an object collection, or data in memory
  4. Offers compile time checking, autocompletion, and Intellisense

There are new features in C# that support LINQ including:
  1. Automatic properties
  2. Initializers
  3. Type Inference
  4. Anonymous types
Automatic properties provide us with a shorthand method for defining a new property. The C# compiler generates to get and set. Initializers reduce the amount of work it takes to create a new instance of a class.
Local variable type inference allow the C# or VB .Net compiler to determine the type of a variable at compile time
Anonymous types allow us to create an object type on the fly.

One of the coolest features in LINQ using VB.Net is XML literals. If you have ever had the experience of creating an XML document using the DOM (Document Object Model) you know that it may be cumbersome to build. It also is difficult to query using XPath. XML literals allow us to copy an paste code into LINQ and the compiler builds the syntax to make this happen. Read on here to read a description of XML literals and how it's done in VB9. In C#, we have to build an add-in to provide this same functionality. The following link describes how to build the Paste XML as XElement addin.

My slide deck can be downloaded here. Let me know what you think!



 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Enter the above security code (required)

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.