Question

Using T-SQL in SQL Server Management Studio this query returns exactly what I am expecting

SELECT * FROM ZipCodeTerritory WHERE ZipCode IS NULL and StateCode = 'WA'

However... the following Linq query returns no results. I've checked the connection string and I have verified I'm connecting to the database. Using a value for the cleanZip variable will return a list. Using a null value, however, never returns anything.

string cleanZip = (item.ToUpper().Equals("NULL") ? null : item.Trim());

var zipCodes = (from z in db.ZipCodeTerritory
                where z.ZipCode.Equals(cleanZip) && z.StateCode.Equals(searchState)
                select z).ToList();

No correct solution

OTHER TIPS

Changed the query to the following and it is working now.

var zipCodes = (from z in db.ZipCodeTerritory
                where (cleanZip == null ? z.ZipCode.Equals(null) : z.ZipCode.Equals(cleanZip)) && z.StateCode.Equals(searchState)
                select z).ToList();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top