How to do use IN operator in LINQ queries?
tforkmann opened this issue · 3 comments
tforkmann commented
I'm trying to convert SqlProvider queries to Dapper.FSharp queries.
In Sqlprovider you can use |=|
as an IN operator in the where clause.
Would be nice if I could do something like that with Dapper.FSharp.
I tried this which obviously does not work:
let getIdsAndDescriptions (conn: IDbConnection)=
task {
let! ids =
select {
for e in enmsTabelle do
join datapoints in enmsSichtDatenpunkte on (e.Sakto = datapoints.Sakto)
where (datapoints.Mandant = int16 999
&& datapoints.USER_KstEbene |=| [|"Contracting";"BGA";"KW"|])
distinct
}
|> conn.SelectAsync<{| Saktobez: string ; Sakto : string ; USER_KstEbene : string |}>
return ids |> Seq.toArray
}
Any idea how to implement that?
JordanMarr commented
This should work.
- I moved the int16 999 outside of the query (prepping "parameters" should happen outside of query to avoid exceptions)
- The "isIn" or "isNotIn" query functions currently require a list
let getIdsAndDescriptions (conn: IDbConnection)=
task {
let mandant = int16 999
let! ids =
select {
for e in enmsTabelle do
join datapoints in enmsSichtDatenpunkte on (e.Sakto = datapoints.Sakto)
where (
datapoints.Mandant = mandant &&
isIn datapoints.USER_KstEbene [ "Contracting";"BGA";"KW" ])
distinct
}
|> conn.SelectAsync<{| Saktobez: string ; Sakto : string ; USER_KstEbene : string |}>
return ids |> Seq.toArray
}
JordanMarr commented
I think I missed your intent. To implement that you would need to stub out the new operator, and then check for it alongside the
isIn
/ isNotIn
MethodCall
handler. That's just a guess - not sure if it would be a straightforward add.
tforkmann commented
Thanks @JordanMarr!
I think the isIn
operator is totally fine.
Didn't know those operators work for then LINQ queries stlye as well.
Closing!