Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WhereSql does not put parentheses around statement leading to unexpected results #704

Open
ueler opened this issue Aug 28, 2024 · 0 comments

Comments

@ueler
Copy link

ueler commented Aug 28, 2024

Hi,

we've been using WhereSql in our project and we noticed it does not put parentheses around the statement. This can lead to unexpected behaviour.

Example

IQueryProvider<User> query = DbAccess.DB.Query<User>();
query = query.Where(u => u.Email.Contains("o"));
query = query.WhereSql("firstname LIKE '%o%' OR lastname LIKE '%o%'");

returns all users where lastname contains 'o', even though it was constrained to email containing 'o'. The rendered query does not have a parentheses around the statement "firstname LIKE '%o%' OR lastname LIKE '%o%'", rendering the email condition useless.

This is in contrast to the following example using pure Where statements

 IQueryProvider<User> query = DbAccess.DB.Query<User>();
query = query.Where(u => u.Email.Contains("o"));
query = query.Where(u => u.FirstName.Contains("o") || u.LastName.Contains("o"));

Here the rendered query does have parentheses around the rendered second condition, not rendering the email condition useless.

This leads to different results, although the intention of both statements was the same.

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

No branches or pull requests

1 participant