Non equijoins using LINQ and F#
f#, linq
Solution
You're going to need to use a cross-join/selectmany (two fors) and a where clause.
E.g.
let results = query {
for i in dc.intervals do
for t in dc.timelines do
where (t.start_time > i.start_time && t.start_time < i.end_time)
select (i, t)
}
Problem
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 ?=?.