I’m implementing a search that will take six possible (but not required) user inputs and then try to match them to some entities.
I think the issue I have come up against is that EF and SQL Server think of nulls as two very different things.
Idea: select an entity where columnA = (if columnA is null then columnA (or null) else searchTerm). The search terms are a mix of ints and strings.
Some code:
entities= (from c in context.Entities
where c.ColumnA == (searchTermA ?? v.ColumnA)
where c.ColumnB == (searchTermB ?? v.ColumnB)
select new
{
v.Property,
}).ToList();
If all columns do not contain nulls, entities are returned. However, I do not get expected results if the column has nulls.
How can I work around this?
Richard
This is what i used to handle null values. It was the only way i could get the right results.