Accepted answer

Instead of


would it be sufficient to use

    string sqlCommand = dataContext.GetCommand(result).CommandText; 


If the expression does not generate valid Sql, this should throw a NotSupportedException, but it does not actually execute the sqlCommand.


I think this will solve your problem:

IQueryable<TEntity> table = GetTable<TEntity>();  
IQueryable<TEntity> result;
    return table.Where(searchExpression).ToList();
catch (NotSupportedException)
    //trying to perform in-memory search if query could not be constructed
    return table

So the method returns is the expression is converted to valid SQL. Otherwise it catches the exception and runs the query in memory. This should work but it doesn't answer your question if it's possible to check if a specific searchExpression can be converted. I don't think such a thing exists.

Related Query

More Query from same tag