RTFM you idiot (me)

 

Have I told you lately that reading manuals is good thing? Wow, what a discovery! Believe me, reading the documentation, manuals, MSDN will save you time. One day spend on reading about .NET Framework fundamentals will save you 2 of debugging, and wandering why… I’ve recently found a nasty behavior in my search by example routine. I thought that I know enough about NHibernate to use find by example in discoverable mode (its when you are programming with Intelisense as your help and guide ;). My code looked like this:

  Customer exampleCustomer = new Customer();
  exampleCustomer.FirstName = view.FirstName;
  exampleCustomer.LastName = view.LastName;
  string[] excludeProps = new string[] { };
  CustomerList customerList =
    customerDao.GetByExample(
      exampleCustomer, excludeProps);

Nothing extraordinary. Right? the exampleCustomer object gets the FirstName and LastName property from view. Than without excluding any property I went to GetByExample to get what I wanted. It worked! Until the customer without FirstName (a company). What did I get when view.FirstName was = “”? A list of all customers with first name matching the attribute with last name ignored! Why? Because the NHibernate reference manual says:

rtfm

“By default, null valued properties and properties which return empty string from the call to ToString() are excluded”.

Right!

Leave a Reply

Your email address will not be published. Required fields are marked *