I can't seem to figure out how to make a LINQ query with where clauses based on multiple nullable variables work. I've tried the "if" methods I've seen on this site, and I get the error:
The name I doesn't exist in the current context.
The "Point" fields are formatted as "POINT(num1, num2)" and work fine in a SQL query.
query = from i in _db.ILV
join p in _db.PC on
i.PostCode equals p.PostCode
select i;
if (!string.IsNullOrEmpty(key))
query = query.Where(i = i.Description.Contains(key));
if(!string.IsNullOrEmpty(rng))
query = query.Where(i => STGeomFromText(i.Point).STDistance(q.Point) <= rng);
if (!string.IsNullOrEmpty(cat))
query = query.Where(i = i.CategoryID.ToInt(cat));
if(!string.IsNullOrEmpty(sub))
query = query.Where(i = i.SubCategoryID.ToInt(sub));
return query;
STGeomFromTextandSTDistancedeclared? where isqdeclared?