I want to create predicate expression so that it translates into WHERE clause with SQL parameter, e.g.:
WHERE e.Id = @id_1;
I have this code
int id = 1;
Expression<Func<Entity, int>> keySelector = e => e.Id;
BinaryExpression equals = Expression.Equal(
keySelector.Body,
Expression.Constant(id, keySelector.Body.Type)); //replace this with a variable
var predicate = Expression.Lambda<Func<Entity, bool>>(equals, keySelector.Parameters[0]);
but it translates into:
WHERE e.Id = 1;
which generates new query execution plan for each id.
Does EF core provide some internal mechanism, that I could (should) use, e.g. special subclass of Expression, or ExpressionVisitor?