1

Closed

Disjunction clauses drop last value

description

I have a query like this
var result = eQuery.Where(email => email.subject == "terminal").Where(email => email.sender == "X" || email.sender == "Y" || email.sender == "Z");

As you can see in the last Where part there are 3 values joined with OR and in my select item I see only the first 2 being passed.
It does not repro if the disjunction Where is the first Where clause. It seems like a bug to me.
Closed Dec 8, 2010 at 4:56 PM by mehfuzh
Fixed

comments

mehfuzh wrote Nov 9, 2010 at 11:44 AM

Thanks again purujit , will check it out and keep posted for any updates.
--Regards

purujit wrote Nov 11, 2010 at 6:58 AM

Actually, I think the problem is more general than that. It is basically with multiple predicates in the Where part. I examined the query expression trees generated with different queries and saw that if the where contains multiple predicates the last predicate is dropped along with all the following conditions in the query.

purujit wrote Nov 11, 2010 at 7:15 AM

I forgot to add an example. For the following query, I don't see a node in the expression tree for email.subject == "Purujit" part. This seems to repro only in the query method syntax.

var result = eQuery.
            Where(email => email.keyword == "Purujit").
            Where(email => email.sender == "Purujit" || email.receivers == "Purujit" || email.subject == "Purujit");

purujit wrote Nov 13, 2010 at 12:07 AM

Okay, I have identified a potential solution. In the createquery method, if you already have a node that means you have already processed a Where call earlier. If the current call is another Where you need to make the AND the previous expression tree with the current Where method's expression tree. That's what I am trying to do by adding a new parent Node of type AND. So far it worked for the queries I threw at it.
            TreeNode parentNode = null;
            // Create a new bucket when Query<T>.Execute is called or it is empty for current type.
            if ((!Buckets.ContainsKey(typeof(T).FullName)) || Buckets.Current.IsAlreadyProcessed)
            {
                Buckets.Current = BucketImpl<T>.NewInstance.Describe();
            }
            else if (curentMethodcall.Method.Name == MethodNames.Where)
            {
                parentNode = ProcessCurrentNode(null, CompoundOperator.And);
            }

            Buckets.Current.IsAsc = curentMethodcall.Method.Name == MethodNames.Orderbydesc ? false : true;

            if (curentMethodcall.Arguments.Count == 2)
            {
                VisitExpression<TS>(curentMethodcall.Arguments[curentMethodcall.Arguments.Count - 1], 0, parentNode);
            }
        }

mehfuzh wrote Dec 8, 2010 at 4:56 PM

Hi There,
You are right about the issue , it is patched in the most recent commit at :
https://github.com/mehfuzh/LinqExtender

Please check it out.

Regards,
Mehfuz