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);

   }
}

 

Published 16 September 05 11:17 by Dinesh.Kulkarni

Comments

# Philippe Leybaert said on September 16, 2005 3:10 PM:
When you call db.SubmitChanges(), does it only generate the SQL statement to update the column [UnitsInStock], or will it update all columns?

If only [UnitsInStock] is updated, how does the compiler/runtime know that only this field has changed? (since it is a field, and not a property with a set accessor)
# Dan Miser said on September 16, 2005 9:22 PM:
Could you clarify something? According to the description under "C# LINQ Tech Preview" on http://msdn.microsoft.com/netframework/future/linq/, it says "Note: this preview works only with the Visual Studio 2005 Release Candidate." We received the RC version at PDC. However, after installing RC and this LINQ Tech Preview from the web (not the one on disc 4), my LINQ projects don't work anymore.

To confuse matters even more, I found this snippet in C:\Program Files\LINQ Preview\Docs\ReadMe.htm: "The prototype compilers and samples will not function on builds later than Beta 2. Note that this means you must not be running the RC0 build of Visual Studio included in the PDC kit."

So, should I just go back to Beta 2, or will there be an update for the LINQ preview soon?

Thanks,
Dan Miser
# Dan Miser said on September 17, 2005 12:13 AM:
I tried commenting before, and it didn't take. You might want to take a look at this link for some problems with the deliverables:
http://distribucon.com/blog/archive/2005/09/16/761.aspx
# Dinesh s Cyberstation Code for my DLinq Demo at PDC | Indoor Grills said on June 1, 2009 3:27 PM:

PingBack from http://indoorgrillsrecipes.info/story.php?id=5301

# Dinesh s Cyberstation Code for my DLinq Demo at PDC | fix my credit said on June 16, 2009 10:07 PM:

PingBack from http://fixmycrediteasily.info/story.php?id=14978

New Comments to this post are disabled

About Dinesh.Kulkarni

I am a program manager in the Visual C# Product Unit of Microsoft. I am currently working on the LINQ project with specific responsibility for DLinq. Previously, I have been in a PM in SQL Server working on ObjectSpaces and DataSet. In pre-MS life, I have worked for companies ranging from startup to IBM on a wide range of software projects. Before I started working, I did M.S.E.E. and Ph.D. (CSE) from the University of Notre Dame and B.Tech. E.E. from IIT Bombay, India.
Page view tracker