nullable check first ?

the example Associations code on http://www.linqpad.net/WhyLINQBeatsSQL.aspx reads
where p.Customer.Address.State == "WA" || p.Customer == null
surely the 2nd condition should be checked first
where p.Customer == null || p.Customer.Address.State == "WA"

Comments

  • A good question. What you say would be true if this was a LINQ-to-objects query. Unless you first checked for p.Customer being null, you could end up with a NullReferenceException.

    But because this is a LINQ-to-SQL query, the LINQ is translated into a SQL statement, and the C# code is never executed.
  • fair nuff, but I would still prefer my version (sorry but it just shouts WRONG at me)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!