Cannot check for null values in sql database.
Using F # query syntax, I am trying to get all records where a specific field is not null, but I cannot figure out how.
At first I tried simply:
query {
for h in dc.Table do
where (h.SectorId <> null)
select h
}
But the error indicated The type 'Nullable<Guid>' does not have 'null' as a proper value. To create a null value for a Nullable type use 'System.Nullable()'.
So, replacing null
with Nullable()
as suggested, I used:
query {
for h in dc.Table do
where (h.SectorId <> Nullable())
select h
}
When I use the above query in LINQPad, it doesn't retrieve any values, even though I know they exist. The problem occurs in the generated SQL:
-- Region Parameters
DECLARE @p0 UniqueIdentifier = null
-- EndRegion
SELECT [t0].[Id], [t0].[Name], [t0].[SectorId], [t0].[Blah], [t0].[Meh], [t0].[DisplayOrder]
FROM [Table] AS [t0]
WHERE [t0].[SectorId] <> @p0
Of course this won't work, because it NULL <> NULL
will always be false in SQL; where to read WHERE [t0].[SectorId] is not null
. How can I check for null in F # queries?
source to share