Using the F# query syntax I'm trying to get all the records where a certain field is not null, but I can't seem to figure out a way of doing this.
First, I attempted just:
query {
for h in dc.Table do
where (h.SectorId <> null)
select h
}
But an error stated The type 'Nullable<Guid>' does not have 'null' as a proper value. To create a null value for a Nullable type use 'System.Nullable()'. Thus, replacing the 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 does not retrieve any values, even though I know they exist. The issue appears to be in the SQL created:
-- 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 will not work because NULL <> NULL in SQL will always be false; the where should read WHERE [t0].[SectorId] is not null. How can I check against null in F# queries?
Try
query {
for h in dc.Table do
where h.SectorId.HasValue
select h
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With