Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non equijoins using LINQ and F#

Tags:

linq

f#

I am trying to join two tables using LINQ and F# using the greater-than operator. This question is essentially the same as the one asked here, but using F# instead of C#.

In my case I have two tables in an SQL Server database : intervals and timelines, both of which have fields start_time and end_time.

I need to perform a non-equijoin on these two tables, matching the start and end times in each table. I have tried doing this as follows:

let dc = new TypedDataContext()

let qry = 
query {
    for i in dc.intervals do 
    join t in dc.timelines on 
      (t.start_time > i.start_time && t.start_time < i.end_time)
    select (i, t)
}

But this predictably fails with the error :

Invalid join relation in 'join'. Expected 'expr expr', where is =, =?, ?= or ?=?.

like image 420
Russell Avatar asked Mar 20 '23 12:03

Russell


1 Answers

Although the F# LINQ docs don't mention it, the C# docs (second paragraph) state that joins using the join keyword are always equijoins. It's probably safe to assume the behavior is consistent across the two languages. @ildjarn suggested a workaround.

like image 81
Daniel Avatar answered Mar 27 '23 10:03

Daniel