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

ExecuteDelete missing parenthesis #224

Closed
jasonlaw opened this issue Jul 4, 2023 · 4 comments
Closed

ExecuteDelete missing parenthesis #224

jasonlaw opened this issue Jul 4, 2023 · 4 comments

Comments

@jasonlaw
Copy link

jasonlaw commented Jul 4, 2023

Hi @rivantsov ,

The execution query is missing parenthesis which could have different results.

var query = session
        .EntitySet<IAuthSession>()
        .Where(x => (x.Id == authSession.Id) || (x.IdentityId == authSession.IdentityId && x.Expires < MyApp.UtcNow));
 session.ExecuteDelete<IAuthSession>(query);

From log:

DELETE FROM "vrewards_dev1"."AuthSession"
WHERE "Id" = @p0 OR "IdentityId" = @p1 AND "Expires" < @p2;
-- Parameters: @p0='01H4HHVCP2KG4WPXBHBCG3FCDD', @p1='$01H4GA9VFWMRXEBW699XSZVKZR', @p2=[2023-07-04T22:55:38]
-- Time 5.6967 ms, [2023/07/04 22:55:38]

@rivantsov
Copy link
Owner

I think the translation is correct. it all based on Oper precedence I think. Try duplicating last part with OR:
... ... && (x.Expires < MyApp.UtcNow || x.Expires < MyApp.UtcNow)

see if parenthesis appear

@jasonlaw
Copy link
Author

jasonlaw commented Jul 5, 2023

Not sure if this is what you are looking for, but the result is still not right to me.

            var query = context
                            .GetSession()
                            .EntitySet<IAuthSession>()
                            .Where(x => (x.Id == authSession.Id) || (x.IdentityId == authSession.IdentityId && (x.Expires < MyApp.UtcNow || x.Expires < MyApp.UtcNow)));
            context.GetSession().ExecuteDelete<IAuthSession>(query);

DELETE FROM "vrewards_dev1"."AuthSession"
WHERE "Id" = @p0 OR "IdentityId" = @p1 AND ("Expires" < @p2 OR "Expires" < @p3);
-- Parameters: @p0='01H4JFPQRE725391TX95EZ577X', @p1='$01H4GA9VFWMRXEBW699XSZVKZR', @p2=[2023-07-05T07:38:33], @p3=[2023-07-05T07:38:33]
-- Time 3.5525 ms, [2023/07/05 07:38:33]

@rivantsov
Copy link
Owner

then I am puzzled, what is wrong with the result for you? Remember that "=" is operation too, and it has the highest precedence value. AND has higher precedence than OR; so SQL is equivalent to source expression even without parenthesis

@jasonlaw
Copy link
Author

jasonlaw commented Jul 5, 2023

Ahhh...I didn't aware of the operator precedence...sorry about that.....
Thank you so much for the clarification, and sorry again for the confusion.

@jasonlaw jasonlaw closed this as completed Jul 5, 2023
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

2 participants