I am trying to use this Linq expression
Dim ex2 As Expression(Of Func(Of Advertisement, Boolean)) =
Function(a) a.Address.CountryCode = ISO AndAlso a.Address.Region = EmptyString
in this manner
Dim ltest = (From a In db.Advertisements.AsExpandable().Where(ex2)).ToList
but it produces these crazy where conditions
DECLARE @p__linq__0 NVARCHAR (MAX) = N'US';
DECLARE @p__linq__1 NVARCHAR (MAX) = N'';
SELECT [Extent1].[AdvertisementID] AS [AdvertisementID],
[Extent1].[URL] AS [URL],
[Extent1].[Address_AddressID] AS [Address_AddressID],
[Extent1].[Business_BusinessID] AS [Business_BusinessID]
FROM [dbo].[Advertisements] AS [Extent1]
LEFT OUTER JOIN [dbo].[Addresses] AS [Extent2]
ON [Extent1].[Address_AddressID] = [Extent2].[AddressID]
WHERE (([Extent2].[CountryCode] = @p__linq__0)
OR (([Extent2].[CountryCode] IS NULL)
AND (@p__linq__0 IS NULL)))
AND (([Extent2].[Region] = @p__linq__1)
OR (([Extent2].[Region] IS NULL)
AND (@p__linq__1 IS NULL)))
I don't know why it produces @p__linq__1 IS NULL
when my parameters are strings and not nullables.
I expect it to produce something like
WHERE [Extent2].[CountryCode] = @p__linq__0 AND [Extent2].[Region] = @p__linq__1
I tried the same thing using LinqKit predicates instead of expressions but got the same results. I actually have a much more complex query with additional where clauses but when it didn't work i broke it down to just this simple query and found the where clause was nothing like what I intended.
So the question is what is the proper way to produce a simpler where clause similar to what I entended using LinqKit expressions or predicates?