Posts Tagged ‘LINQ’

The LINQ (Language-Integrated Query)

Wednesday, March 25th, 2009

LINQ is a combination of namespaces and C# 3.0 language enhancements. LINQ provides a high-level abstraction of virtually any data and emulates the query operations of the relational model. The LINQ Project seems to be just the beginning of many other future dramatic enhancements to .NET and .NET languages.

LINQ has three major components:

  1. LINQ to Objects
  2. LINQ to ADO.NET, which includes
    • LINQ to DataSet (originally called LINQ over DataSet) LINQ to Entities
    • LINQ to SQL (originally called DLinq)
  3. LINQ to XML (originally called XLinq)
To start playing with LINQ, first install it from here.

and here is sample of code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Query;
using System.Xml.XLinq;
using System.Data.DLinq;

namespace Linq
{

[Table]
public class Customers
{
[Column(Id=true)]
public string customerId;
[Column]
public string companyName;
[Column]
public string city;
[Column]
public string country;
}

class Program
{
static void Main(string[] args)
{
// connection string
string connString = @"server = .\sqlexpress;integrated security = true; database = northwind ";
// create data context
DataContext db = new DataContext(connString);

// create typed table
Table customers = db.GetTable();

// query database
var custs =
from c in customers
select
c
;

// display customers
foreach (var c in custs)
Console.WriteLine(
"{0} {1} {2} {3}",
c.customerId,
c.companyName,
c.city,
c.country
);
}
}
}

ahd that is all.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in