What you are trying to do is not feasible. It's not that it can not do (can not even, directly) that doing would be a mistake. You are potentially causing a race condition , that is, between one query and another it may be that the condition is not the same. This is more or less how you check if a file exists to open it. When it opens, it may no longer exist.
If you read what you wrote in the question you will already have the solution: "I need to check if there is a record in the table". So do this. Is the filtro
variable what you need to check? Then it is ready, if it is not, add to the SQL expression.
You should only count if you need the count. Clearly you're saying you want something else. Apparently you're hurting the performance thinking you're getting better. Improving robustness. And doing something semantically wrong.
Even though I need the count afterwards, I would still do it via C # code to avoid the mentioned race condition. But apparently you do not even need this.
As much as you want to do otherwise, you're making a mistake. You may not like this answer but it's the only one valid for your situation.