InfoQ

News

LINQ Examples Posted

Posted by Marcie Jones on Aug 31, 2006

Community
.NET
Topics
.NET Framework ,
Data Access
Tags
LINQ

Scott Guthrie has posted the materials from his recent Language INtegrated Query (LINQ) talk at Tech Ed Australia.  For those looking for detailed code samples to understand LINQ further, download these materials. PowerPoint slides are also included in the download for those who want an overview, and even the slides contain quite a bit of code.

LINQ is a set of extensions for .NET to provide a powerful, native query syntax for C# and VB, allowing developers to perform SQL-like queries against any .NET collection or drop down to raw SQL when needed.  LINQ can also query XML and any LINQ result sequence can be databound to ASP.NET controls.  LINQ for entities (formerly described as "ObjectSpaces") is available with the August ADO.NET CTP.  LINQ is currently planned for release with C# 3.0 / VB9 / Visual Studio Orcas / the .NET framework version tentatively known as 3.5.

Example of a LINQ query:

string [] cities = { “Auckland”, “Oslo”, “Sydney”,
       “Seattle”, “Paris”, “Los Angeles” };

IEnumerable places = from city in cities
       where city.Length > 5
             orderby city descending
       select city;


Further reading on LINQ:

Beware HTML syntax by Matthias Ernst Posted Sep 3, 2006 2:34 AM
Re: Beware HTML syntax by Jonathan Allen Posted Sep 8, 2006 11:14 PM
Amazing! by Tomasz Blachowicz Posted Sep 5, 2006 9:50 AM
I have a site dedicated to LINQ by Joe Rattz Posted Sep 13, 2006 12:56 PM
LINQ in Action samples source code by Fabrice Marguerie Posted Mar 4, 2008 5:26 PM
  1. Back to top

    Beware HTML syntax

    Sep 3, 2006 2:34 AM by Matthias Ernst

    There's probably a <string> missing between 'IEnumberable' and 'places'.

  2. Back to top

    Amazing!

    Sep 5, 2006 9:50 AM by Tomasz Blachowicz

    I think the LINQ is amazing. Basically it's one of the most amazing features I've ever seen. I'm a big fan of Hibenrate's HQL query, but LINQ looks like HQL on steroids plus XQuery! I wonder how this stuff is implemented.

    Take a look at this video: channel9.msdn.com/showpost.aspx?postid=114680

  3. Back to top

    Re: Beware HTML syntax

    Sep 8, 2006 11:14 PM by Jonathan Allen

    That is correct. Alternately, you can use "var" instead of giving it an explicit type. This new syntax looks like dynamic typing, but in fact is statically checked at runtime.

  4. Back to top

    I have a site dedicated to LINQ

    Sep 13, 2006 12:56 PM by Joe Rattz

    Please feel free to come visit.

    www.linqdev.com

  5. Back to top

    LINQ in Action samples source code

    Mar 4, 2008 5:26 PM by Fabrice Marguerie

    If you want to see more LINQ examples, you can download for free the complete source code for all the samples from the LINQ in Action book. The samples for all the 14 chapters are provided in both C# and VB.NET.

Educational Content

Confessions of A New Agile Developer

This short article is a first-person case history of someone taking up Agility for the first time. It covers the problems and reactions that are common to most teams and most developers.

Scott Chacon on Git and GitHub

Scott Chacon talks about the technologies that power GitHub (Erlang, Redis,...), and the benefits of Git as a version control and as a storage system. Also: ShowOff, a JS-based presentation tool.

Reformulating the Product Delivery Process

Israel Gat, Erik Huddleston and Stephen Chin present how Inovis realized a higher product throughput by using three unconventional Kanban practices and a Lean Release Management tool called APROPOS.

Enterprise Mashups: Why Do I Care?

Ross Mason discusses how to use enterprise mashups by applying a number of patterns, such as FeedFactory, Super Search, and Pipeline, in order to find new ways to benefit from existing enterprise data

Command-Query Responsibility Segregation

Udi Dahan discusses the Command Query Responsibility Segregation (CQRS) pattern, detailing on queries and commands, what they are and how they should be used in an asynchronous programming environment

The Story of a Project

Olivier Mallassi shares a story of a typical software development project, some typical problems and what he learned from Tom Demarco about addressing those problems, and an alternative story.

Living and Working with Aging Software

Ralph Johnson discusses principles, practices and tools relating to software development starting from already existing code which needs refactoring, maintenance, and sometimes architectural change.

IIBA Debate on the Role of the Analyst in Agile Projects

At a recent IIBA New Zealand members event Shane and Pete debated the role of the business analyst on Agile projects. They looked at the importance of analysis on projects and how the role changes.