HasValue on a nullable DateTime produces incorrect sql

Posts   
 
    
Jez
User
Posts: 198
Joined: 01-May-2006
# Posted on: 16-Jun-2008 15:17:26   

Hi Frans

The logic for "HasValue" when using nullable types seems to be incorrect - item.HasValue should generate "IS NOT NULL" but generates "IS NULL" instead.

This query against northwind should produce 830 results, but instead produces 0:

var linq = new LinqMetaData(adapter);
var query =  from o in linq.Order
            where o.Freight.HasValue
            select o;

Here's the SQL:


SELECT DISTINCT 
[LPLA_1].[OrderID] AS [OrderId], 
[LPLA_1].[CustomerID] AS [CustomerId], 
[LPLA_1].[EmployeeID] AS [EmployeeId], 
[LPLA_1].[OrderDate], 
[LPLA_1].[RequiredDate], 
[LPLA_1].[ShippedDate], 
[LPLA_1].[ShipVia], 
[LPLA_1].[Freight], 
[LPLA_1].[ShipName], 
[LPLA_1].[ShipAddress], 
[LPLA_1].[ShipCity], 
[LPLA_1].[ShipRegion], 
[LPLA_1].[ShipPostalCode], 
[LPLA_1].[ShipCountry] 
FROM 
[Northwind].[dbo].[Orders] [LPLA_1]  
WHERE ( ( ( ( [LPLA_1].[Freight] IS NULL))))

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 16-Jun-2008 16:15:54   

You use the latest build?

Frans Bouma | Lead developer LLBLGen Pro
Jez
User
Posts: 198
Joined: 01-May-2006
# Posted on: 16-Jun-2008 17:12:22   

Yes

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 16-Jun-2008 18:39:29   

Reproduced.

Obvious workaround: test for null. (field!=null)

(edit) Fixed in next build.

Frans Bouma | Lead developer LLBLGen Pro