Skip to content

Conversation

@PeterN
Copy link

@PeterN PeterN commented Oct 22, 2022

This is my solution for #670. This works in the same way for SqlExpression evaluation as SqlBuilder's ReuseParameters, except it is always on.

This is helpful for e.g. search parameters. Currently, query.Where(x => x.Field1.Contains(search) || x.Field2.Contains(search) || x.Field3.Contains(search)) will duplicate the search parameter each time, resulting in a WHERE clause looking like WHERE [Field1] LIKE '@0' OR [Field2] LIKE '@1' OR [Field3] LIKE '@2'.

With this change applied, this example would become WHERE [Field1] LIKE '@0' OR [Field2] LIKE '@0' OR [Field3] LIKE '@0'.

This works in the same way for SqlExpression evaluation as SqlBuilder's
ReuseParameters, except it is always on.
@schotime
Copy link
Owner

Its a tiny bit more complex than that, because if the column type you are querying against is different but the value is the same, then you will get errors, as the parameter can't be reused against multiple types.

This is why it was turned off, as it can't be controlled, however we could be smarter in the linq provider as you know the type you are querying against and could reuse ones of the same type. At least you might have a better chance of getting it right anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants