The problem I believe comes from the way F# Set
implements method Contains
. It belongs to ICollection
interface and this fact somehow upsets LINQ-to-SQL query builder.
If you explicitly force your Contains
into the extension method of IEnumerable
territory everything gets OK:
let customerNumbers = set ["12345"; "23456"; "3456"]
let customerQuery = query {
for c in dataContext.Customers do
where((customerNumbers :> IEnumerable<string>).Contains(c.CustomerNumber))
select c
}
Or, equivalently, you can add non-LINQ-to-SQL query
let idQuery = query { for id in customerNumbers do select id }
which has no problems with enumerating set
yielding seq<string>
and then use it for Contains
as
....
where (idQuery.Contains(c.CustomerNumber))
....
Or, to begin with, you may keep your customerNumbers
as seq
:
let customerNumbers = set ["12345"; "23456"; "3456"] |> Set.toSeq
and use it as intuition prompts:
....
where(customerNumbers.Contains(c.CustomerNumber))
....