Code for my DLinq Demo at PDC

Here is the code for my demo during David Campbell's (DAT200, 11am Wednesday) session titled "Future Directions for Data-Driven Applications ...". Of course I don't have the video for showing the code in multiple steps starting from scratch. But here is the final code with query update etc.

You can run this with the PDC LINQ Preview bits. If you came to PDC, you have it on DVD. If not, just download it from our site. All it needs is Visual Studio 2005 beta2 with SQL Server 2005 (it is an option when you install VS beta2).

using System;
using System.Collections.Generic;
using System.Query;
using System.Data.DLinq;

[Table(Name = "Products")]
class Product
{

   [Column(Id=true)]
public int ProductID;

   [Column]
public short UnitsInStock;

   [Column]
public int SupplierID;

   [Column]
public string ProductName;

}

class

Northwind : DataContext
{

   public Table<Product> Products;

   public Northwind(string s) : base(s) { }

}

class

Driver
{

   static void Main(string[] args)
{

      Northwind db =
new Northwind(@"c:\Northwind\Northwnd.mdf");

      db.Log = Console.Out;

      int x =3;

      var query = from p in db.Products
where p.SupplierID == x
orderby p.UnitsInStock

      select p;

      Product sauce = query.First();

      Console.WriteLine("\nID={0}\tStock={1}\tName={2}\n",
sauce.ProductID,
sauce.UnitsInStock,
sauce.ProductName);

      sauce.UnitsInStock += 10;

      db.SubmitChanges();

      Console.WriteLine("--------\n");

      Console.WriteLine("Post-SubmitChanges() results\n");

      foreach (var p in query)
Console.WriteLine("\nID={0}\tStock={1}\tName={2}\n",
p.ProductID, p.UnitsInStock, p.ProductName);

   }
}