Question about the Where operator AND and OR
newbienewbie opened this issue · 3 comments
newbienewbie commented
Hi, Dzoukr. Thanks for your awesome library.
I need compose multiple WHERE conditions:
let x = select {
for e: Customer in customerTable do
where (e.firstname = "S") // 1st where condition
}
let meetSomeCondition = true // some condition
let y =
if not meetSomeCondition then x
else {
x with
Where = x.Where + Column("Age", Gt 3) // 2nd where condition
}
y |> conn.SelectAsync<Customer>
However, I'm confused about the operator AND & OR defined for the Where Type:
type Where =
| Empty
| Column of string * ColumnComparison
| Binary of Where * BinaryOperation * Where
| Unary of UnaryOperation * Where
| Expr of string
static member (+) (a, b) = Binary(a, And, b)
static member (*) (a, b) = Binary(a, Or, b)
static member (!!) a = Unary (Not, a)
- The
+
reminds me of sum type like DU which is often interpreted as IN EITHER CASE . Sounds more like OR instead of AND. - While the
*
make me think of product type like tuple, which is often interpreted as we should have both. Sounds more like AND instead of OR.
Is there any reason why (+)
is chosen for AND & (*)
is chosen for OR ?
Dzoukr commented
Hello @newbienewbie, there is already discussion around this here #37
I think, in a long term, I should mark these operators as obsolete and use traditional LINQ &&
and ||
newbienewbie commented
I'm sorry I should search the issues before asking :(
Dzoukr commented
No problem at all. :) Thanks for using this library 👍