FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Database Blog: LINQ and ASP.NET
DATABASE
EXCEPTION::QUERY

A Blog About Database Products and Technology.

by Kevin Carlson
SELECT * FROM [Musings]

Database matters.

by Niklas Hemdal
May 16, 2006

LINQ and ASP.NET

Scott Guthrie (ScottGu) blogs about using LINQ with ASP.NET. LINQ is Language Integreted Query. Lest you think this is some sort of embedded SQL hack, let me assure you, LINQ is an entirely new way to access your data.

Using LINQ, your database code is integrated into your traditional code in a very cool way. For example, from ScottGu's blog, a Page_Load for a simple "Hello World" page:

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Query;

public partial class Step1 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)
{
string[] cities = { "London", "Amsterdam",
"San Francisco", "Las Vegas",
"Boston", "Raleigh", "Chicago", "Charlestown",
"Helsinki", "Nice", "Dublin" };

GridView1.DataSource = from city in cities
where city.Length > 4
orderby city
select city.ToUpper();

GridView1.DataBind();
}
}

The cool thing is this line:

GridView1.DataSource = from city in cities
where city.Length > 4
orderby city
select city.ToUpper();

It looks like you are setting the DataSource to a variant of SQL inside your C# code. Cooler still is that you can use CLR function like ToUpper() on the variables that are part of the statement.

Deep inside, all of this "magic" is actually backed up by methods on the objects that are called in an entirely reasonable way. There are changes to C# and VB.NET that allows this magic to work. More details on those sorts of things when I more fully understnad them ;).

The LINQ May CTP is here.

Posted by Douglas Reilly at 06:13 PM  Permalink




 
INFO-LINK