Wednesday, April 25, 2007

Digging DLINQ

Just gave DLINQ a quick shot and it indeed is quite impressive. The way Table and Column attributes are used for database mapping is similar to that of XML Serialization:


    public class Product



        public int ProductID { get; set; }



        public string ProductName { get; set; }



        public decimal UnitPrice { get; set; }


Now, you can use LINQ syntax to perform strong typed database query:

public static void DLinqQuery()


    string ConnStr =



    DataContext ctx = new DataContext(ConnStr);

    Table<Product> prods = ctx.GetTable<Product>();


    //this is COOL!

    var list = from p in prods

               where p.UnitPrice > 30

               select p;


    foreach (var p in list)



            p.ProductID, p.ProductName, p.UnitPrice);



Pretty neat, agree? I only wish this were available eailier so that I didn’t have to deal with typed dataset. That was aweful… Some further point of interests:

  • Is the underlying SQL generated by DLINQ effecient? (IQueryable and the expression tree do deserve their own blog entries).
  • Mapping between foreign key relationship to object graphs.
  • Stored Proc and Transaction support