0

I have the following Nhibernate LINQ query:

var query = from c in session.Query<Customer>()
            where
                c.EmailAddress == customer.EmailAddress ||
                (
                    c.Address1 == customer.Address1 &&
                    c.City == customer.City &&
                    c.State == customer.State &&
                    c.Postal == customer.Postal &&
                    c.FirstName == customer.FirstName &&
                    c.LastName == customer.LastName
                )
                select c;

I expected the resulting SQL statement to look like:

select
    ...
from
    dbo.Customers customer0_ 
where
    customer0_.EmailAddress=@p0 or 
    (
        customer0_.Address1=@p1 
        and customer0_.City=@p2 
        and customer0_.State=@p3 
        and customer0_.Postal=@p4 
        and customer0_.FirstName=@p5 
        and customer0_.LastName=@p6;
    )

But what I see from the debug log is:

select
    ...
from
    dbo.Customers customer0_ 
where
    customer0_.EmailAddress=@p0 
    or customer0_.Address1=@p1 
    and customer0_.City=@p2 
    and customer0_.State=@p3 
    and customer0_.Postal=@p4 
    and customer0_.FirstName=@p5 
    and customer0_.LastName=@p6;

Notice there is no grouping on the address part of the where clause. Is this intentional? Should I be formatting my query a different way, or is this a bug?

3
  • I suspect you need to upgrade to 3.2 (or latest from trunk) as 3.1 linq was not fully featured. Commented Mar 23, 2012 at 6:17
  • The assembly with this code was referencing 3.1 (came with Fluent Nhibernate nuget package), but the main project was referencing 3.2, with a binding redirect, so the actual live code should have been using 3.2, no? Commented Mar 23, 2012 at 13:08
  • 1
    possible duplicate of Grouping in condition is being dropped Commented Mar 24, 2012 at 16:08

1 Answer 1

1

The generated SQL is correct; the parentheses are not needed.

Sign up to request clarification or add additional context in comments.

1 Comment

Absolutely correct, but thanks for including the link in the comments that explains exactly why.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.