Search code examples
f#type-providersf#-3.0

F# join with IQueryable


I am experimenting with using F# query expression to retrieve data from database. For the following code:

1   let q = query{
2       for i in dataContext.Incident do
3       select i
4   }
5   
6   let q2 = query{
7       for i in dataContext.Incident do
8       select i
9   }
10  
11  let q3 = query{
12      for i in q do
13      join i2 in q2
14      on(i.IncidentId = i2.IncidentId)
15      select i
17  }

I am getting error as Incorrect syntax for join at line 13.

Are there any way to solve this problem?


Solution

  • F# being a whitespace-sensitive language, this is just an indentation issue; either of the following should work:

    let q3 = query {
        for i in q do
        join i2 in q2 on (i.IncidentId = i2.IncidentId)
        select i
    }
    
    let q3' = query {
        for i in q do
        join i2 in q2 on
            (i.IncidentId = i2.IncidentId)
        select i
    }