The basic concept of nullable type is... the underlying type will have all the values specified in its range + a null value, to increase the flexibility with the database programming.
nullable types has two readonly properties
1) HasValue 2) Value
HasValue is boolean type and it is set to true automatically if Value has some value in it.
So, for comparisions, you have to use HasValue first and then Value. If u use Value directly, and if it is null, then the above exception will be thrown.
keeping these in mind, I doubt this fragment too,. where invoiceNumber == null
you should try invoiceNumber.Value==null (not invoiceNumber)
or
where invoiceNumber.HasValue && p.InvNumber == invoiceNumber.Value
thanks
invoiceNumber.HasValue?