Hi,
You can write something like this (« and » do exactly the same thing as <@ and >@):

1
2
3
4
5
6
7
let q = 
  « { for p in §db.Products 
      for c in §db.Categories 
      when p.CategoryID =?! c.CategoryID
        && c.CategoryName = "Beverages"
      -> (p.ProductName, c.CategoryName) } 
    |> orderBy (fun (p,c) -> p ) » 

This sample uses two nested fors to select all products and all categories and filter tuples where product belongs to a category (so it's what Join does). The "=?!" operator allows using a Nullable on the left side and selects only non-null values. If you want to include null values, you can decaler & use the following operator:

1
2
[<ReflectedDefinition>]
let (=??!) x y = (x =?! y) || not x.HasValue

It demonstrates join only on two tables, but extending it to three shouldn't be difficult. You can just add one more for and one more condition to when. Alternatively, you can use groupBy function (see the dlinqsamples.fs in the F# distribution for more info), but I recommend this syntax as I think it is more readable and more compac.

Finall, I should mention that there are a few bugs in the latest FLINQ sample release, so there are some troubles when executing it. I reported all the errors to the F# team, so it will be hopefully fixed soon. I can send you a version of flinq.dll compatible with VS 2008 beta 2, where the code above runs fine, but it is not perfect and the sample with 2 joins doesn't work. :-(

Both LINQ and FLINQ are still beta versions, so it is not completed... But I hope this post will help when it will be finished.

By on 8/17/2007 6:59 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper