The binary operator OrElse is not defined for the types 'System.Nullable`1[System.Boolean]' and 'System.Boolean'.

Posts   
 
    
Kodiak
User
Posts: 92
Joined: 13-Apr-2009
# Posted on: 21-Nov-2010 13:58:10   

Hi,

I'm trying to query back to retrieve Deliveries that may match a specified date range. This range may be null/Nothing so I've tried to use the various checks of Is Nothing or .HasValue = False before performing the checks but an exception is always thrown.

      Dim lDeliveries = (From delivery As DeliveryEntity In lMeta.Delivery _
                                  Where delivery.Active = True 
                                   AndAlso (delivery.DeliveryDate >= mSearchStartDate.Value OrElse mSearchStartDate.HasValue = False) _
                                   Order By delivery.Site.Name, delivery.Site.StreetAddress.City
                                   Select delivery)

It's working if I use the following code but it's not quite as elegant


            If (mSearchStartDate.HasValue) Then lUnscheduledDeliveries = lUnscheduledDeliveries.Where(Function(delivery As DeliveryEntity) delivery.DeliveryDate >= mSearchStartDate)

I've donwloaded and am using the latest version of LLBLGen currently available.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-Nov-2010 23:11:04   

This is copied from documentation:

(VB users note) To filter on Nothing (null), it's necessary to use the field instead of the '.Value' property, though this is ok, as the VB.NET compiler doesn't wrap these expressions with a coalesce statement:

Dim lDeliveries = (From delivery As DeliveryEntity In lMeta.Delivery _
     Where delivery.Active = True 
     AndAlso (delivery.DeliveryDate >= mSearchStartDate.Value 
          OrElse mSearchStartDate = Nothing) _
     ...
David Elizondo | LLBLGen Support Team