fsprojects / SQLProvider

A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
https://fsprojects.github.io/SQLProvider
Other
564 stars 144 forks source link

Union with Linq.Contains generated invalid SQL query #739

Closed b0wter closed 2 years ago

b0wter commented 2 years ago

I have an issue while trying to union two queries. The queries both work well if used on their own. However, combining them by query1.Union(query2) causes the resulting SQL statement to be invalid.

Here are the two queries:

let ofGroup (ctx: sql.dataContext) (groupId: Guid) =
    query {
        for person in ctx.Public.Persons do
        where (person.GroupNo = Some groupId)
        select person
    }

let findByIds (ctx: sql.dataContext) (personIds: Guid list) =
    query {
        for person in ctx.Public.Persons do
        where (personIds.Contains(person.personNo)) 
        select person
    }

and this is the SQL statement:

SELECT [...] FROM "public"."persons" as "person" WHERE (("person"."group_no" = @param1)) UNION SELECT [...] FROM "public"."persons" as "person" WHERE (("person"."person_no" IN ())) 

It's missing the list of group ids.

b0wter commented 2 years ago

Nvm, completely my mistake. Just took me an hour to notice :expressionless: