Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grouping in condition is being dropped

LINQ to NHibernate removes parenthesis in where clause:

session.Query<MyEntity>().Where(x => (x.MyProp1 < end && x.MyProp1 > start) ||
                                     (x.MyProp2 < end && x.MyProp2 > start));

This results in the following query (note the missing parenthesis):

select <columns> from MY_ENTITY where MY_PROP1 < :p0 and MY_PROP1 > :p1 or 
                                      MY_PROP2 < :p2 and MY_PROP2 > :p3;

This is a huge problem, because it changes the query condition significantly.

Is this a known problem or am I doing something wrong?

like image 502
Daniel Hilgarth Avatar asked Feb 15 '12 16:02

Daniel Hilgarth


People also ask

What is grouping in pandas?

What is the GroupBy function? Pandas' GroupBy is a powerful and versatile function in Python. It allows you to split your data into separate groups to perform computations for better analysis.

How can Pandas drop rows based on multiple conditions?

We can drop single or multiple columns from the dataframe just by passing the name of columns and by setting up the axis =1.

How do I delete a Pandas group?

In the pandas series constructor, there is a method called drop() which is used to remove specified rows from the pandas series object. It won't update the original series object with deleted rows instead of updating the original series object, it will return another series object with the removed rows.


1 Answers

Because AND has a higher precedence in order of operations over OR the parenthesis are not needed, so the query provider doesn't add in the redundant information.

To help remember orders of operations, a boolean AND is considered analogous to multiplication (on a binary value) and OR is considered analogous to addition on binary values. When dealing with boolean algebra (in a non-programming environment) it is actually not uncommon to use * for AND and + for OR.

like image 143
Servy Avatar answered Sep 20 '22 10:09

Servy