Previous month:
January 2008
Next month:
March 2008

February 2008

C# v.next

C# is a changing language. C# 1.0 was all about core component-support. With C# 2.0 generics have been added. C# 3.0 added LINQ and extensions that are very useful with LINQ such as extension methods, object initializer, collection initializer, anonymous types....

What about the next version of C#?
One important part is using of types defined by dynamic languages such as IronRuby or IronPython.

The C# team considers the keyword dynamic that's shown in the blog of Charlie Calvert: Future Focus 1: Dynamic Lookup

Christian


LINQ with joins

Dan Wahlin posts about LINQ and Lambdas and Sprocs... Oh My! With his post he defines a complex LINQ query to join several tables from the Northwind database:


public IEnumerable GetOrderDetails(int orderID) {
  NorthwindDataContext db = this.DataContext;
  IEnumerable orderDetails =
    from o in db.Orders
    where o.OrderID == orderID
    join s in db.Shippers on o.ShipVia equals s.ShipperID
    join od in db.OrderDetails on o.OrderID equals od.OrderID
    join p in db.Products on od.ProductID equals p.ProductID
    join supplier in db.Suppliers on p.SupplierID equals supplier.SupplierID
    let total = od.Quantity * od.UnitPrice
    select new OrderDescription
    {
      Product = p.ProductName,
      Quantity = od.Quantity,
      ShipperName = s.CompanyName,
      Total = total,
      UnitPrice = od.UnitPrice,
      SupplierName = supplier.CompanyName
    };
  return orderDetails;
}


Instead of using joins with the LINQ query expression it is also possible to use compound from and access shipper and supplier (with a * to 1 relation) directly:

public IEnumerable GetOrderDetails(int orderID)
{
  NorthwindDataContext db = this.DataContext;
  IEnumerable orderDetails =
    from o in db.Orders
    where o.OrderID == orderID
    from od in o.OrderDetails
    let total = od.Quantity * od.UnitPrice
    select new OrderDescription
    {
      Product = od.Product.ProductName,
      Quantity = od.Quantity,
      ShipperName = o.Shipper.CompanyName,
      Total = total,
      UnitPrice = od.UnitPrice,
      SupplierName = od.Product.Supplier.CompanyName
    };
  return orderDetails;
}

I think the LINQ query with compound from is the simpler one.

Christian