3

Consider the following two tables, with 3 columns each:

Table 1:

a INTEGER NOT NULL,
b INTEGER NOT NULL,
c INTEGER NOT NULL

Table 2:

d INTEGER NOT NULL,
e INTEGER,
f INTEGER NOT NULL

I'm trying to write a query expression that joins the two tables on a 2 part, composite key: (b, c) = (e, f).

I know that if column e was not Nullable I could just write:

query {
    for r1 in c.table1 do
    join r2 in c.table2 on ((r1.b, r1.c) = (r2.e, r2.f))
    .
    .
}

But how do I do it if column e is Nullable but column b in not?

siki
  • 9,077
  • 3
  • 27
  • 36
  • Shot in the dark, but what happens if you try `r2.e.Value` instead of `r2.e` inside the tuple? – kvb Jun 26 '14 at 19:21
  • Well, I think the same thing as if I do `((Nullable(r1.b), r1.c) = (r2.e, r2.f))`: basically an exception if `r2.e` is `Null`. What I think we need here is a `Nullable` tuple type, so that the `?=` can be used. – siki Jun 26 '14 at 19:27
  • What exception do you see using `Nullable(r1.b)`? It shouldn't be a null reference exception since equality comparisons are valid even on nulls. – kvb Jun 26 '14 at 19:33
  • @kvb: It's an `InvalidOperationException`. – siki Jun 26 '14 at 19:35
  • Thrown when the query is compiled to SQL or when the results are requested? Is it the same exception when you do `r2.e.Value`? – kvb Jun 26 '14 at 19:46
  • 1
    I'm sorry this is my bad. The exception occurs because I call `head` in the query exception after the join and the sequence is empty. So I guess `Nullable(r1.b)` does actually work. – siki Jun 26 '14 at 20:10

0 Answers0