Freigeben über


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

   }
}

Comments

  • Anonymous
    September 16, 2005
    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)

  • Anonymous
    September 16, 2005
    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 FilesLINQ PreviewDocsReadMe.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

  • Anonymous
    September 16, 2005
    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

  • Anonymous
    June 01, 2009
    PingBack from http://indoorgrillsrecipes.info/story.php?id=5301

  • Anonymous
    June 16, 2009
    PingBack from http://fixmycrediteasily.info/story.php?id=14978